Proud Merchants
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 7069 Accepted Submission(s): 2944
The merchants were the most typical, each of them only sold exactly one item, the price was Pi, but they would refuse to make a trade with you if your money were less than Qi, and iSea evaluated every item a value Vi.
If he had M units of money, what’s the maximum value iSea could get?
Each test case begin with two integers N, M (1 ≤ N ≤ 500, 1 ≤ M ≤ 5000), indicating the items’ number and the initial money.
Then N lines follow, each line contains three numbers Pi, Qi and Vi (1 ≤ Pi ≤ Qi ≤ 100, 1 ≤ Vi ≤ 1000), their meaning is in the description.
The input terminates by end of file marker.
2 10 10 15 10 5 10 5 3 10 5 10 5 3 5 6 2 7 3
5 11
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int maxn = 5005;
int dp[maxn];
struct product{
int q,p,v;
int d;
}pro[505];
bool cmp(product x,product y){
return x.d > y.d;
}
int main(void){
int n,m;
while(scanf("%d%d",&n,&m)!=EOF){
memset(dp,0,sizeof(dp));
for(int i = 0;i < n; i ++){
scanf("%d%d%d",&pro[i].p,&pro[i].q,&pro[i].v);
pro[i].d = pro[i].p - pro[i].q;
}
sort(pro,pro + n,cmp);
int cur = m;
for(int i = 0 ;i < n ;i ++ ){
for(int j = m;j >= pro[i].p; j--){
if(j >= pro[i].q)
dp[j] = max(dp[j],dp[j - pro[i].p] + pro[i].v );
else
break;
}
}
printf("%d\n",dp[m]);
}
}
419



被折叠的 条评论
为什么被折叠?



