标签:
Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 28468 Accepted Submission(s): 10023
#include<stdio.h> #include<string.h> int c[250005],temp[250005]; int num[55],cost[55]; int main(){ int n; while(scanf("%d",&n)!=EOF){ if(n<0) break; memset(c,0,sizeof(c)); memset(temp,0,sizeof(temp)); memset(num,0,sizeof(num)); memset(cost,0,sizeof(cost)); int sum=0; for(int i=0;i<n;i++){ scanf("%d%d",&cost[i],&num[i]); sum+=cost[i]*num[i]; } int total=sum/2; for(int i=0;i<=num[0];i++){ c[i*cost[0]]=1; 。///初始化的时候特别注意 } for(int i=1;i<n;i++){ for(int j=0;j<=sum;j++){ for(int k=0;k+j<=sum&&k/cost[i]<=num[i];k+=cost[i]) temp[k+j]+=c[j]; } for(int ii=0;ii<=sum;ii++){ c[ii]=temp[ii]; temp[ii]=0; } } int i; for( i=total;i>=0;i--){ if(c[i]) break; } printf("%d %d\n",sum-i,i); } return 0; }
标签:
原文地址:http://www.cnblogs.com/13224ACMer/p/4672732.html