标签:des style blog http color java os io
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 14758 Accepted Submission(s):
6229
1 #include<stdio.h> 2 #include<iostream> 3 #include<string.h> 4 #include<algorithm> 5 using namespace std; 6 const int M=1000; 7 int cost[M],weight[M],num[M],dp[M]; 8 int main() 9 { 10 int t,V,n,i,j,k; 11 scanf("%d",&t); 12 while(t--) 13 { 14 scanf("%d %d",&V,&n); 15 for(i=1; i<=n; i++) 16 scanf("%d %d %d",&cost[i],&weight[i],&num[i]); 17 memset(dp,0,sizeof(dp)); 18 for(i=1; i<=n; i++) 19 { 20 for(j=1; j<=num[i]; j++)//对于每类的大米,转化为01背包 21 { 22 for(k=V; k>=cost[i]; k--) 23 { 24 dp[k]=max(dp[k],dp[k-cost[i]]+weight[i]); 25 } 26 } 27 } 28 printf("%d\n",dp[V]); 29 } 30 return 0; 31 }
标签:des style blog http color java os io
原文地址:http://www.cnblogs.com/lxm940130740/p/3914186.html