// https://www.luogu.com.cn/problem/P1466
// 背包
#include<bits/stdc++.h>
using namespace std;
int val[40], f[40][1005];//f[i][j]在前i个数中选取和能到j的方案数
int main() {
f[0][0] = 1;
int n, sum = 0;
cin >> n;
for(int i = 1; i <= n; i++) {
sum += i;
val[i] = sum;
}
if(sum % 2) cout << "0\n";
else {
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= val[i]; j++) {
if(j >= i) f[i][j] = f[i - 1][j - i] + f[i - 1][j];// 选这个数和不选
else f[i][j] = f[i - 1][j];// 选不了
}
}
cout << f[n][sum / 2] << '\n';
}
return 0;
}
标签:Subset,www,cn,int,luogu,P1466,Sums,com
From: https://blog.csdn.net/release_lonely/article/details/136852877