标签:des style blog http color io os ar java
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2191
Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 15308 Accepted Submission(s):
6499
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 5 using namespace std; 6 7 int Max(int a,int b) 8 { 9 return a>b?a:b; 10 } 11 12 int main () 13 { 14 int t,dp[5010]; 15 scanf("%d",&t); 16 17 while (t--) 18 { 19 memset(dp,0,sizeof(dp)); 20 int n,m; 21 int p[210],h[210],c[210]; 22 scanf("%d%d",&n,&m); 23 for (int i=0; i<m; i++) 24 { 25 26 scanf("%d%d%d",&p[i],&h[i],&c[i]); 27 } 28 for (int i=0; i<m; i++) 29 { 30 for (int j=1; j<=c[i]; j++) 31 { 32 for (int k=n; k>=p[i]; k--) 33 { 34 dp[k]=Max(dp[k],dp[k-p[i]]+h[i]); 35 } 36 } 37 } 38 printf ("%d\n",dp[n]); 39 } 40 return 0; 41 }
hdu 2191悼念512汶川大地震遇难同胞——珍惜现在,感恩生活(改编01背包)
标签:des style blog http color io os ar java
原文地址:http://www.cnblogs.com/qq-star/p/4035433.html