01 backpack, 01 backpack Problems

Source: Internet
Author: User

01 backpack, 01 backpack Problems

Input

Each test point (input file) has only one set of test data.

The first act of each group of test data is two positive integers N and M, indicating the number of prizes and the number of prizes in the small Ho hands.

The next n rows describe each row to describe a prize. The I behavior contains two integers: need (I) and value (I). The meaning is described in the previous article.

Test data guarantee

For 100% of data, the value of N cannot exceed 500, and the value of M cannot exceed 10 ^ 5.

For 100% of data, need (I) cannot exceed 2*10 ^ 5, and value (I) cannot exceed 10 ^ 3

Output

For each group of test data, an integer Ans is output, indicating the total preference value that small Ho can obtain.

Sample Input
5 1000144 990487 436210 673567 581056 897
Sample output
2099

# Include <stdio. h> # define maxn limit 5int dp [maxn]; int max (int a, int B) {return a> B? A: B;} int main () {int N, M, I, w, v, j; scanf ("% d", & N, & M ); for (I = 0; I <N; ++ I) {scanf ("% d", & w, & v); for (j = M; j> = w; -- j) dp [j] = max (dp [j], dp [j-w] + v);} printf ("% d \ n ", dp [M]); return 0 ;}


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.