hdu 1709 The Balance
2012-08-10 11:00
274 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1709
View Code
View Code
/* 砝码称重 */ #include<stdio.h> #include<string.h> int f(int x,int y) { if(x>y) return x-y; else return y-x; } int main() { int n; int p[10010]; int sum[10010]; int temp[10010]; int a[105]; int i,j,k,l; int totall; while(~scanf("%d",&n)) { int count=0; l=0; memset(sum,0,sizeof(sum)); memset(temp,0,sizeof(temp)); totall=0; for(i=1;i<=n;i++) { scanf("%d",&a[i]); totall+=a[i]; } sum[a[1]]=1; sum[0]=1;//注意不要漏这个初始化 for(i=2;i<=n;i++) { for(j=0;j<=totall;j++) { for(k=0;k<=a[i];k+=a[i]) { temp[j+k]+=sum[j]; temp[f(j,k)]+=sum[j];//砝码不一定放在一边 } } for(j=0;j<=totall;j++) { sum[j]=temp[j]; temp[j]=0; } } for(i=1;i<=totall;i++) { if(sum[i]==0) { count++; p[l++]=i; } } if(count) { printf("%d\n",count); printf("%d",p[0]); for(i=1;i<l;i++) printf(" %d",p[i]); printf("\n"); } else printf("0\n"); } }
相关文章推荐
- [母函数]HDU 1709 The Balance
- HDU 1709 The Balance [母函数]
- hdu 1709 The Balance (母函数)
- HDU 1709 The Balance
- HDU 1709 The Balance(母函数)
- HDU 1709 The Balance【负次方母函数】
- hdu 1709 The Balance
- HDU 1709 母函数天平问题 可出现减法的情况 The Balance
- HDU1709 The Balance(母函数,有限制的)
- hdu 1709 The Balance(母函数)
- HDU 1709 The Balance 母函数
- hdu 1709——The Balance
- hdu 1709 The Balance 正负背包(01背包)
- hdu 1709 The Balance
- HDU 1709 The Balance
- hdu 1709 The Balance(母函数)
- 解题报告:HDU_1709 The Balance
- HDU 1709-The Balance(母函数的应用)
- HDU1709_HDU 1709 The Balance(母函数/生成函数)
- hdu 1709 The Balance