Getting started with HDU 1114 piggy-bank full backpack

Source: Internet
Author: User

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

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.