标签:
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 6652 Accepted Submission(s): 2730
#include<stdio.h> #include<string.h> #include<math.h> int num[10005]; int ans[10005]; int c[10005],temp[10005]; int main(){ int n; while(scanf("%d",&n)!=EOF){ memset(num,0,sizeof(num)); memset(c,0,sizeof(c)); memset(ans,0,sizeof(ans)); memset(temp,0,sizeof(temp)); int total=0; for(int i=0;i<n;i++){ scanf("%d",&num[i]); total+=num[i]; } for(int i=0;i<=num[0];i+=num[0]) c[i]=1; for(int i=1;i<n;i++){ for(int j=0;j<=total;j++){ for(int k=0;k+j<=total&&k/num[i]<=1;k+=num[i]){///注意《=1 temp[j+k]+=c[j]; temp[(int)fabs(j-k)]+=c[j];//注意此刻应当考虑负值的情况 } } for(int ii=0;ii<=total;ii++) c[ii]=temp[ii]; } int cnt=0; for(int i=1;i<=total;i++){ if(!c[i]){ cnt++; ans[cnt]=i; } } printf("%d\n",cnt); for(int i=1;i<=cnt;i++){ printf("%d%c",ans[i],i==cnt?‘\n‘:‘ ‘); } } return 0; }
HDU 1709 母函数天平问题 可出现减法的情况 The Balance
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/4674290.html