题目:https://www.luogu.org/problemnew/show/P1466
dp水题。
#include<iostream> #include<cstdio> #include<cstring> #define ll long long using namespace std; const int N=43,M=785; ll n,dp[N][M],sm[N]; void init() { for(int i=1;i<=n;i++) sm[i]=sm[i-1]+i; } int main() { scanf("%lld",&n); init(); if(sm[n]&1)printf("0"); else { dp[0][0]=1; for(int i=1;i<=n;i++) for(int j=0;j<=sm[i];j++) { if(j-i>=0)dp[i][j]+=dp[i-1][j-i]; if(sm[i-1]-j>=0)dp[i][j]+=dp[i-1][sm[i-1]-j]; } printf("%lld",dp[n][sm[n]/2]/2); } return 0; }