标签:lang nbsp i++ code http view lap end div
分析:dp[i][j]表示前i个数能够组成j的对数,可得dp[i][j]=dp[i-1][j]+dp[i-1][j-i],所以最后dp[n][sum/2]既是所求
1 /* 2 PROB:subset 3 ID:wanghan 4 LANG:C++ 5 */ 6 #include "iostream" 7 #include "cstdio" 8 #include "cstring" 9 #include "string" 10 using namespace std; 11 const int maxn=50; 12 const int maxm=1000; 13 int a[maxn],n,ans,cnt; 14 int dp[maxn][maxm]; 15 int main() 16 { 17 freopen("subset.in","r",stdin); 18 freopen("subset.out","w",stdout); 19 cin>>n; 20 int sum=0; 21 for(int i=1;i<=n;i++){ 22 sum+=i; 23 } 24 if(sum%2){ 25 cout<<"0"<<endl; 26 }else{ 27 ans=sum/2; 28 for(int i=1;i<=n;i++) 29 dp[i][0]=1; 30 for(int i=1;i<=n;i++){ 31 for(int j=1;j<=ans;j++) 32 dp[i][j]=dp[i-1][j]+dp[i-1][j-i]; 33 } 34 cout<<dp[n][ans]<<endl; 35 } 36 }
标签:lang nbsp i++ code http view lap end div
原文地址:http://www.cnblogs.com/wolf940509/p/7197129.html