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 ;}