01リュックサック(並べ替え)

6488 ワード

http://acm.hdu.edu.cn/showproblem.php?pid=3466
Prodd Mercehance
Time Limit:2000/1000 MS(Java/Others)    Memory Limit:131313712/65536 K(Java/Others)Total Submission(s):9596    Acceepted Submission(s):4032
Problem Description
Recently,iSea went to an ancint country.For such a long time,it was the most wealthy and powerful king dom in the world.As a reult,the people in this country are still proudy productive ef.the fen theirthwarn.harn.harn.harn。
The merchangets were the most typical、each of them only sonid exactly one item、the price was Pi、but they would refuse to make a trade with you if your money werse less than Qi、and iSea evaluted everry.Vilue.Vilue.Vilue.
If he had M units of money、what’s the maximvalue iSea could get?
 
 
Input
The re 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.
The n N LINE 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 maker.
 
 
Output
For each test case,output one integer,indicating maximvalue iSea could get.
 
 
Sample Input
2 10 10 15 10 5 10 3 10 5 10 5 5 5 5 5 5 5 5 5 5 5 6 2 7 3
 
 
Sample Output
5 11
 
 
Author
iSea@WHU
 
 
ソurce
2010 ACM-ICPC Multi-University Training Conteest(3)——Host by WHU
https://www.cnblogs.com/nwpuacmteams/articles/5777815.html
 
//#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include 
#include <string>
#include 
#include 
#include 
#include ;
#include 
#include <set>
#include <string.h>
#include 
#define ME(x , y) memset(x , y , sizeof(x))
#define SF(n) scanf("%d" , &n)
#define rep(i , n) for(int i = 0 ; i < n ; i ++)
#define INF  0x3f3f3f3f
#define mod 1000000007
#define PI acos(-1)
using namespace std;
typedef long long ll ;
int dp[5009] , s[5009];

struct node
{
    int p , w , val;
}node[509];

bool cmp(struct node a , struct node b)
{
    return a.w - a.p < b.w - b.p ;
}

int main()
{
    int n , v ;
    while(~scanf("%d%d" , &n , &v))
    {
        for(int i = 1 ; i <= n ; i++)
        {
            scanf("%d%d%d" , &node[i].p , &node[i].w , &node[i].val);
        }
        sort(node+1 , node+1+n , cmp);
        memset(dp , 0 , sizeof(dp));

        for(int i = 1 ; i <= n ; i++)
        {
            for(int j = v ; j >= node[i].w ; j--)
            {
                dp[j] = max(dp[j] , dp[j-node[i].p] + node[i].val);
            }
        }
        cout << dp[v] << endl ;
    }

    return 0;
}