Analysis:
First, this question cannot be considered a normal 01 backpack problem, because w <= 10 ^ 9 cannot be opened, so the large array certainly has other ideas, observe that we know that the value of V is very small, and the maximum value is 100. Then we can use this to take the sum of values as the sum of the original quality, but pay attention to the following points: because the question is to find out the greatest value within the range of no more than W quality, and we are seeking the quality with the greatest value, we can understand after careful analysis, we need to store a backpack with a certain value of I as small as possible, so we can analyze it in turn to know that the smaller quality has a large value serial number, which completely satisfies the question, the last point is that each value package (going out to DP [0]) must be initialized to a relatively large number, so that the minimum value can be put. If the initialization is 0, it must be wrong (think about it). This is to fill the backpack completely, but one is infinite... (Why is it like this, because we are looking for it in turn)
Question link http://acm.nyist.net/JudgeOnline/problem.php? PID = 1, 860
Code:
# Include <stdio. h> # include <string. h ># define maxn 0x3f3f3ftypedef struct {int W, V;} STR; STR s [105]; int DP [10050]; int main () {int n, m; while (scanf ("% d", & N, & M) = 2) {// memset (DP, 'B', sizeof (DP )); this is the same as the following, but I don't know why int sum = 0; For (INT I = 0; I <n; I ++) scanf ("% d ", & S [I]. w, & S [I]. v), sum + = s [I]. v; For (INT I = 0; I <= sum; I ++) DP [I] = maxn; // same effect as above DP [0] = 0; for (INT I = 0; I <n; I ++) for (Int J = sum; j> = s [I]. v; j --) {If (DP [J]> DP [J-s [I]. v] + s [I]. w) DP [J] = DP [J-s [I]. v] + s [I]. W ;}for (INT I = sum; I> = 0; I --) if (DP [I] <= m) {printf ("% d \ n ", i); break ;}} return 0 ;}