Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 11596 Accepted Submission(s): 4634
1 #include<iostream> 2 #include<cstring> 3 #include<cstdio> 4 #include<map> 5 #include<queue> 6 #include<stack> 7 using namespace std; 8 int n,m; 9 struct node 10 { 11 int a,c; 12 } N[105]; 13 int f[110005]; 14 int ans; 15 int value[100005],size[100005]; 16 int count; 17 void slove(int q) 18 { 19 count=1; 20 for(int i=1;i<=q;i++) 21 { 22 int c=N[i].c,v=N[i].a; 23 for (int k=1; k<=c; k<<=1) 24 { 25 value[count] = k*v; 26 size[count++] = k*v; 27 c -= k; 28 } 29 if (c > 0) 30 { 31 value[count] = c*v; 32 size[count++] = c*v; 33 } 34 } 35 } 36 int main() 37 { 38 while(scanf("%d %d",&n,&m)!=EOF) 39 { 40 if(n==0&&m==0) 41 break; 42 for(int i=0; i <= m; i++) 43 f[i] = 0; 44 ans=0; 45 for(int i=1;i<=n;i++) 46 scanf("%d",&N[i].a); 47 for(int i=1;i<=n;i++) 48 scanf("%d",&N[i].c); 49 slove(n); 50 for(int i=1;i<count;i++) 51 for(int gg=m;gg>=size[i];gg--) 52 f[gg]=max(f[gg],f[gg-size[i]]+value[i]); 53 for(int i=1;i<=m;i++) 54 if(f[i]==i) 55 ans++; 56 cout<<ans<<endl; 57 } 58 return 0; 59 }
原文:http://www.cnblogs.com/hsd-/p/5447932.html