HDU 3466 Proud Merchants (with sort of 01 backpack)

Source: Internet
Author: User

Proud Merchants

Time limit:2000/1000 MS (java/others) Memory limit:131072/65536 K (java/others)
Total submission (s): 4039 Accepted Submission (s): 1677


Problem descriptionrecently, ISea went to an ancient country. For such a long time, it is the most wealthy and powerful kingdom in the world. As a result, the people in this country is still very proud even if their nation hasn ' t been so wealthy any more.
The merchants were the most typical, each of the them only sold exactly one item, the price is Pi, but they would refuse to M Ake a trade with the 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?

Inputthere is several test cases in the input.

Each test case begin with the integers N, M (1≤n≤500, 1≤m≤5000), indicating the items ' number and the initial mone Y.
Then N lines follow, each line contains three numbers Pi, Qi and Vi (1≤pi≤qi≤100, 1≤vi≤1000), their meaning is I n the description.

The input terminates by end of file marker.

Outputfor each test case, output one integer, indicating maximum value ISea could get.

Sample Input2 1010 15 105 10 53 105 10 53 5 62 7 3

Sample Output511

Authorisea @ whu

Source2010 acm-icpc multi-university Training Contest (3)--host by WHU

Recommendzhouzeyong | We have a carefully selected several similar problems for you:3460 3463 3468 3467 3465 Simple 01 backpack, the order is good, the code is simple. Copy the idea of the great God on the Internet:

Because if an item is 5 9, an item is 5 6, on the first backpack when only dp[9],dp[10],..., dp[m], and then the second to carry the backpack, if it is normal, should borrow the front dp[8],dp[7], but now these values are 0, This can result in an error. So you have to think that only the value of the back to be used before can be obtained, then will not be wrong. Set A:P1,Q1 b:p2,q2, if first a after B, then at least p1+q2 capacity, if the first B after a, at least p2+q1 capacity, then P1+Q2 > p2+q1, after deformation is Q1-P1 < Q2-P2.

So to sort the q-p for each property

Test instructions: Each item has p, Q, V, three attributes, each item's charge is P, but the premise is that there must be q,v is the value obtained.

Attached code:

1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 structnode7 {8     intp,q,v;9} ss[505];Ten  One intMAXS (intAintb) A { -     returnA>b?a:b; - } the BOOLCMP (node A,node b) - { -     returna.q-a.p<b.q-b.p;//key sequencing, see analysis above - } + intMain () - { +     intn,m,i,j; A     intdp[5005]; at      while(~SCANF ("%d%d",&n,&m)) -     { -          for(i=0; i<n; i++) -scanf"%d%d%d",&ss[i].p,&ss[i].q,&ss[i].v); -Sort (ss,ss+n,cmp); -Memset (DP,0,sizeof(DP)); in          for(i=0; i<n; i++) -              for(j=m; j>=ss[i].q; j--) toDP[J]=MAXS (dp[j],dp[j-ss[i].p]+ss[i].v); +printf"%d\n", Dp[m]); -     } the     return 0; *}

HDU 3466 Proud Merchants (with sort of 01 backpack)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.