Poj 1276 cash machine (multiple backpacks)

Source: Internet
Author: User

Cash machine
Time limit:1000 ms   Memory limit:10000 K
Total submissions:26954   Accepted:9533
Question: There are various currencies with different denominations, each of which has different quantities of currencies. Please find the amount of cash that can be used to make up the nearest and less than or equal to the given number. Multiple backpacks turn 0 1 backpack The possible status of currency I is W [I] to cash. State EquationDP [J] = DP [J-C [I] + W [I] (C [I] indicates that "volume" is actually equivalent to W [I] for easy differentiation) Use count [I] to record the usage of the currency in N [I]. Note that before each entry into the inner loop (that is, clear count 0 before currency change)
# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int main () {int cash, num, I, j; int N [15]; int W [15]; int DP [10001]; int count [10001]; while (CIN> cash> num) {for (I = 0; I <num; I ++) CIN> N [I]> W [I]; memset (DP, 0, sizeof DP ); for (I = 0; I <num; I ++) {memset (count, 0, sizeof count); For (j = W [I]; j <= cash; j ++) if (DP [J] <DP [J-W [I] + W [I] & COUNT [J-W [I] <n [I]) {DP [J] = DP [J-W [I] + W [I]; count [J] = count [J-W [I] + 1 ;}} cout <DP [Cash] <Endl;} return 0 ;}

Poj 1276 cash machine (multiple backpacks)

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.