http://acm.hdu.edu.cn/showproblem.php?pid=2602
View Code
1 #include<cstdio> 2 #include<cstring> 3 4 int main( ) 5 { 6 int cases; 7 int i; 8 int j; 9 int nPack; 10 int maxVolume; 11 int weight[1001]; 12 int value[1001]; 13 int record[1001]; 14 15 scanf("%d",&cases); 16 while( cases-- ) 17 { 18 memset(record,0,sizeof(record)); 19 scanf("%d %d",&nPack,&maxVolume); 20 for( i = 0; i < nPack; i++ ) 21 { 22 scanf("%d",&value[i]); 23 } 24 for( i = 0; i < nPack; i++ ) 25 { 26 scanf("%d",&weight[i]); 27 } 28 29 for( i = 0; i < nPack; i++ ) 30 for( j = maxVolume; j >= weight[i]; j-- ) 31 { 32 if( record[j-weight[i]]+value[i] > record[j] ) 33 record[j] = record[j-weight[i]]+value[i]; 34 } 35 36 printf("%d\n",record[maxVolume]); 37 } 38 return 0; 39 }