标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)
Total Submission(s): 4219 Accepted Submission(s): 1740
#include"cstdio" #include"cstring" #include"algorithm" using namespace std; const int MAXN=1005; struct Node{ int P,Q,v; }goods[505]; int n,W; int dp[5005]; int comp(Node a,Node b) { return a.Q-a.P < b.Q-b.P; } int main() { while(scanf("%d%d",&n,&W)!=EOF) { memset(dp,0,sizeof(dp)); for(int i=0;i<n;i++) { scanf("%d%d%d",&goods[i].P,&goods[i].Q,&goods[i].v); } sort(goods,goods+n,comp); for(int i=0;i<n;i++) { for(int j=W;j>=goods[i].Q;j--) dp[j]=max(dp[j],dp[j-goods[i].P]+goods[i].v); } printf("%d\n",dp[W]); } return 0; }
标签:
原文地址:http://www.cnblogs.com/program-ccc/p/5187138.html