HDU 3466 proud merchants (Backpack problem)

Source: Internet
Author: User
Proud merchants

Time Limit: 2000/1000 MS (Java/others) memory limit: 131072/65536 K (Java/Others)
Total submission (s): 1899 accepted submission (s): 762

Problem descriptionrecently, ISEA went to an existing ent 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 wocould refuse to make a trade with you if your money were than Qi, and ISEA evaluated every item A value VI.
If he had m units of money, what's the maximum value ISEA cocould get?

 

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

 

Outputfor each test case, output one integer, indicating maximum value ISEA cocould get.

 

Sample Input

2 1010 15 105 10 53 105 10 53 5 62 7 3
 

Sample output

511
 

 

The price of a product is pi. If your money is equal to or greater than Qi, you can buy the product or the value of VI.

Knapsack Problem: formula DP [J] = DP [J] = math. Max (DP [J], DP [j-k1] + K2 );

 

Import Java. io. *; import Java. util. *; public class main {int n, m, M = 6000; int DP [] = new int [m]; public static void main (string [] ARGs) {New Main (). work ();} void work () {vertex SC = new vertex (New bufferedinputstream (system. in); While (SC. hasnext () {n = SC. nextint (); M = SC. nextint (); node [] = new node [N]; for (INT I = 0; I <n; I ++) {int A = SC. nextint (); int B = SC. nextint (); int c = SC. nextint (); node [I] = new node (A, B, C);} ARRA Ys. sort (node); // for each item, press (this. qi-this.pi)> (O. qi-o.pi) Sort arrays in ascending order. fill (DP, 0); For (INT I = 1; I <= N; I ++) {for (Int J = m; j> = 0; j --) {If (j> = node [I-1]. qi) {int k1 = node [I-1]. pi; int k2 = node [I-1]. VI; DP [J] = math. max (DP [J], DP [j-k1] + K2) ;}} system. out. println (DP [m]) ;}} class node implements comparable <node> {int PI; int qi; int VI; node (INT Pi, int Qi, int VI) {This. pi = PI; this. qi = qi; this. vi = VI;} public int compareto (node O) {retu RN (this. qi-this.pi)> (O. qi-o.pi )? 1:-1 ;}}}

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.