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