View Code
1 #include2 #include 3 #include 4 5 int c[10001],w[10001],f[10001]; 6 int main() 7 { 8 int i, j, n, v; 9 10 while(scanf("%d%d",&n,&v)&&n&&v) 11 { 12 memset(f,0,sizeof(f)); 13 for(i=0; i =c[i]; j--) 19 { 20 f[j] = f[j] > f[j-c[i]]+w[i] ? f[j] : f[j-c[i]]+w[i]; 21 } 22 printf("%d\n",f[v]); 23 } 24 //system("pause"); 25 return 0; 26 } 27