洛谷P1466 集合 Subset Sums_01背包水题
不多解释,适当刷刷水…
Code:
#include<cstdio> #include<algorithm> using namespace std; const int maxn = 10000000 + 3; long long f[maxn]; int main() { int n, sumv = 0; scanf("%d",&n); for(int i = 1;i <= n; ++i) sumv += i; if(sumv % 2 != 0) {printf("0"); return 0;} sumv >>= 1; f[0] = 1; for(int i = 1;i <= n; ++i) for(int v = sumv;v >= i; --v) { f[v] += f[v - i]; } printf("%lld",f[sumv] / 2); return 0; }