HDU3466 Proud merchants[Backpack DP condition limit]

Source: Internet
Author: User

Proud Merchants

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


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 Test instructions: n items have m yuan, item price p, value Q, the condition is more than Q yuan in hand to buy, to seek maximum value Press Q-p Small to big sort then 01 backpackF[i][j] is the first I item J Yuan, only J>qi can buy the first itemso consider the item I, under normal circumstances the smallest can be updated from f[0], now is F[QI-PI], that is to say Qi-pi was wastedthis waste is, of course, as small as possible.
a:p1,q1 b:p2,q2, first select a, you need at least p1+q2 capacity, and first select B will need at least p2+q1, if p1+q2>p2+q1, then to choose two words must first select a then B, the formula can be replaced Q1-P1 < Q2-P2,
first found Qi-pi small, there is no smaller than qi-pi QJ, so that can be from J to IThis ensures that later J-pi are greater than the previous q-p, which is the range of updates that are incrementedJust follow the two comparison routines.

////main.cpp//hdu3466////Created by Candy on 29/10/2016.//copyright©2016 Candy. All rights reserved.//#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<queue>using namespacestd;Const intn=505, m=5005; inlineintRead () {CharC=getchar ();intx=0, f=1;  while(c<'0'|| C>'9'){if(c=='-') f=-1; C=GetChar ();}  while(c>='0'&&c<='9') {x=x*Ten+c-'0'; C=GetChar ();} returnx*F;}intn,m;structitem{intp,q,w; BOOL operator< (ConstItem &r)Const{returnq-p<r.q-R.P;}} A[n];intF[m];voiddp () {memset (F,0,sizeof(f));  for(intI=1; i<=n;i++)         for(intj=m;j>=a[i].q;j--) F[j]=max (f[j],f[j-a[i].p]+a[i].w);}intMainintargcConst Char*argv[]) {     while(SCANF ("%d%d", &n,&m)! =EOF) {         for(intI=1; i<=n;i++) {a[i].p=read (); A[i].q=read (); a[i].w=read ();} Sort (a+1, A +1+N);        DP (); printf ("%d\n", F[m]); }    return 0;}

HDU3466 Proud merchants[Backpack DP condition limit]

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.