3466.Proud Merchants

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.
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?

 

Input
There are several test cases in the input.

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.

 

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

 

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
tip:变形的背包问题
(开坑,完全搞懂就回来填)

#include

#include

#include

using namespace std;

struct data

{

    int P;

    int Q;

    int V;

}input[510];

int cmp(data a,data b) { return (a.Q-a.P) < (b.Q-b.P);}

int dp[5100];

int main()

{

    int N,M;

    while (scanf("%d%d",&N,&M)!=EOF)

    {

        int n,m;

        memset(dp, 0, sizeof(dp));

        for (n=0;ncin >> input[n].P >>input[n].Q >>input[n].V;

        sort(input,input+N,cmp);

        for (n=0;n

            for (m=M;m>=input[n].Q;m--)

                dp[m]=max(dp[m],dp[m-input[n].P]+input[n].V);

        cout << dp[M]<<endl;

    }

    return 0;

}

你可能感兴趣的:(HUD,OJ,DP)