This question is about money-saving pig, empty quality W1, money quality W2, and then the value and weight of various types of money, asking how much money a piggy bank needs to store is a classic topic for getting started with a full backpack. Now I don't fully understand it. Let's talk about my understanding. The full backpack is to put every kind of data in it as much as possible, and every kind of data is put to the maximum value. (For Shenma, can we put every kind of data to the maximum? Objective: Continue.) Finally, let's see that all types are put in and put to the maximum value. Okay. As for Shenma, putting it in front of the backend is a 0-1 backpack, that is, only one backend is allowed, and it depends on the front, because if from W [I]-W, In the 0-1 backpack, when w-w [I]> W [I], it is possible that W [I] has been put into DP [w, that is, the full backpack, so we put W [I] Again, which is obviously not consistent with the 0-1 backpack, and this is exactly what the full backpack needs, so, the computing sequence of a 0-1 backpack is different from that of a full backpack. Over
# Include <stdio. h> # include <string. h> int W1, W2, V [505], W [505], n, DP [10005], W; int INF = 1000000000; int min (int A, int B) {return a <B? A: B;} void dp () {for (INT I = 1; I <= W; ++ I) DP [I] = inf; DP [0] = 0; // do not forget. For (INT I = 1; I <= N; ++ I) for (Int J = W [I]; j <= W; ++ J) DP [J] = min (DP [J-W [I] + V [I], DP [J]);} int main () {int T; scanf ("% d", & T); While (t --) {scanf ("% d", & W1, & W2); W = W2-W1; scanf ("% d", & N); For (INT I = 1; I <= N; ++ I) scanf ("% d ", & V [I], & W [I]); DP (); If (DP [w] <inf) printf ("the minimum amount of money in the piggy-bank is % d. \ n ", DP [w]); else puts (" This is impossible. ");} return 0 ;}