输入n,把1-n分成两个和相等的子集,有多少种分法

想了个dp,直接背包也行

#include <iostream>
#include <cstdio>

using namespace std;

int dp[55];

int main() {
    int n;
    scanf("%d", &n);
    int s = n * (n + 1) / 2;
    if(s & 1) {
        puts("0");
        return 0;
    }
    s >>= 1;
    dp[0] = 1;
    for(int j = 1; j <= n; j++)
        for(int i = s; i >= j; i--)
            dp[i] += dp[i-j];
    printf("%d\n", dp[s] >> 1);
    return 0;
}
View Code

相关文章:

  • 2021-08-09
  • 2021-12-21
  • 2021-12-05
  • 2021-08-14
  • 2021-11-24
猜你喜欢
  • 2022-12-23
  • 2021-12-17
  • 2021-05-30
  • 2021-09-20
  • 2022-12-23
  • 2021-09-14
  • 2021-08-12
相关资源
相似解决方案