HDU 3466 Proud Merchants

Source: Internet
Author: User

Proud merchantstime limit:1000msmemory limit:65536kbthis problem would be judged onHDU. Original id:3466
64-bit integer IO format: %i64d Java class name: Main Recently, 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 Input
2 1010 15 105 10 53 105 10 53 5 62 7 3
Sample Output
511
SourceACM-ICPC multi-university Training Contest (3)--host by WHU: This is what Chen Guolin's csdn blog says: for (I=1; i<=n; i++)
for (j=m; j>=q[i]; j--)
Dp[j]=max (Dp[j],dp[j-p[i]]+v[i]);
To ensure that the DP equation does not have any validity j-p[i] must be compared to J first, then when the calculation I, the minimum can be counted to q[i]-p[i], so that the latter can be used to the front of the state, so the order of q[i]-p[i] can be guaranteed no effect. This is a good idea, indeed!
1#include <bits/stdc++.h>2 using namespacestd;3 Const intMAXN =505;4 intn,m,dp[5010];5 structnode{6     intp,q,v;7     BOOL operator< (ConstNode &t)Const{8         returnQ-p < T.Q-T.P;9     }Ten }D[MAXN]; One intMain () { A      while(~SCANF ("%d%d",&n,&M)) { -Memset (DP,0,sizeofDP); -          for(inti =0; i < N; ++i) thescanf" %d%d%d", &d[i]. P,&d[i]. q,&D[i]. V); -Sort (d,d+N); -          for(inti =0; i < N; ++i) { -              for(intj = M; J >= D[i]. Q; --j) +DP[J] = max (Dp[j],dp[j-d[i]. P] +D[i]. V); -         } +printf"%d\n", Dp[m]); A     } at     return 0; - } - /* - 3 Ten - 5 5 - 2 7 3 in 3 5 6 - */
View Code

HDU 3466 Proud Merchants

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.