练习三 Problem X

Problem Description
Recently, iSea went to an ancient country. For such a long time, it was the most wealthy and powerful kingdom in the world. As a result, the people in this country are still very proud even if their nation hasn’t been so wealthy any more.<br>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.<br>If he had M units of money, what’s the maximum value iSea could get?<br><br>

Input
There are several test cases in the input.<br><br>Each test case begin with two integers N, M (1 ≤ N ≤ 500, 1 ≤ M ≤ 5000), indicating the items’ number and the initial money.<br>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.<br><br>The input terminates by end of file marker.<br><br>

Output
For each test case, output one integer, indicating maximum value iSea could get.<br><br>

Sample Input
2 10 10 15 10 5 10 5 3 10 5 10 5 3 5 6 2 7 3

Sample Output
5 11

<span style="font-size:14px;color:#6600cc;background-color: rgb(255, 255, 255);">#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int MAXN=550;
struct Node
{
int p,q,v;
}node[MAXN];
int dp[5500];
bool cmp(Node a,Node b)
{
return a.q-a.p<b.q-b.p;
}
int main()
{
int n,m,i,j;
while(cin>>n>>m)
{
for(int i=0;i<n;i++)
scanf("%d%d%d",&node[i].p,&node[i].q,&node[i].v);
sort(node,node+n,cmp);
memset(dp,0,sizeof(dp));
for(i=0;i<n;i++)
for(j=m;j>=node[i].q;j--)
dp[j]=max(dp[j],dp[j-node[i].p]+node[i].v);
printf("%d\n",dp[m]);
}
return 0;
}</span>

• 本文已收录于以下专栏：

指针练习--变量交换H

Description 注：本题只需要提交填写部分的代码 用指针变量对两个整数按从小到大排序。 #include int main() {     int *p1,*p2,*p;     int a...
• l769255844
• 2015年12月27日 16:56
• 331

专题三 Problem X

• ML_ACM
• 2016年05月31日 21:55
• 118

练习三 Problem N

Problem Description 我们看到过很多直线分割平面的题目，今天的这个题目稍微有些变化，我们要求的是n条折线分割平面的最大数目。比如，一条折线可以将平面分成两部分，两条折线最多可以将平面...
• ibingyu
• 2016年05月28日 19:39
• 177

练习三 Problem J

• ibingyu
• 2016年05月27日 21:46
• 97

练习三 Problem L

• ibingyu
• 2016年05月27日 22:08
• 90

练习三 Problem D

Problem Description A number whose only prime factors are 2,3,5 or 7 is called a humble number. The...
• ibingyu
• 2016年05月28日 20:21
• 112

练习三 Problem M

Problem Description 有一头母牛，它每年年初生一头小母牛。每头小母牛从第四个年头开始，每年年初也生一头小母牛。请编程实现在第n年的时候，共有多少头母牛？ Input ...
• ibingyu
• 2016年05月28日 19:30
• 119

练习三 Problem O

Problem Description Give you a number on base ten,you should output it on base two.(0 < n < 10...
• ibingyu
• 2016年05月28日 19:56
• 108

练习三 Problem C

• ibingyu
• 2016年05月16日 17:41
• 116

练习三 Problem V

Problem Description The aspiring Roy the Robber has seen a lot of American movies, and knows that th...
• ibingyu
• 2016年05月29日 11:21
• 116

举报原因： 您举报文章：练习三 Problem X 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)