[Usaco2007 DEC] gemstone bracelet [01 backpack] [WATER]

Source: Internet
Author: User
Description

While she was hanging out in a jewelry store, she bought a favorite bracelet. Naturally, she wants to pick out the best pieces of N (1 <= n <= 3,402) gemstone she collects on the bracelet. For the part I gem, its weight is w_ I (1 <= w_ I <= 400 ), and Bessie knows the charm value d_ I (1 <= d_ I <= 100) that it can add to himself after being inlaid with a bracelet ). Because Bessie can only endure bracelets weighing less than M (1 <= m <= 12,880), she may not be able to pin all her favorite gems. So Bessie found you and told you about the attributes of all her gems and the weight that she could endure. I hope you can help her calculate and embed the gems according to the most reasonable scheme, her charm value can be increased at most.

Input

* Row 1st: two integers separated by spaces: N and m

* 2nd .. line n + 1: I + 1 Act 2 integers separated by spaces: w_ I and d_ I, respectively, the weight of the I-th gem and the charm value that can be added to Bessie

Output

* Row 3: Output 1 integer, indicating the charm value that Bessie can increase at most according to the mosaic requirements.

Sample input4 6
1 4
2 6
3 12
2 7

Input description:

Bessie collected four gems and she was able to endure the bracelet with a maximum weight of 6.


Sample output23

Output description:

Bessie put all the other gems except the second gem into the bracelet so that she could increase
4 + 12 + 7 = 23 charm value, and the weight of all the gems is 1 + 2 + 3 <= 6, also meets the requirements.

 

Question:

01 backpack ==and I am still very convinced

Then, I decided to have a good workout today ..

I practiced it once through water questions.

 

MARK:

When a brute-force program tests a topic such as DP, you can test small data, and big data runs too slowly;

Then there's nothing strange about it.

 

I am too lazy to attach the code ..

[Usaco2007 DEC] gemstone bracelet [01 backpack] [WATER]

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.