POJ 1276 Cash Machine (multiple backpack)

Source: Internet
Author: User

Cash Machine
Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 26954 Accepted: 9533
Main topic:There are a variety of currencies with different denominations. Each denomination has a different number of currencies, please find out the amount of the nearest and less equal to the given number cash that can be used to make the money. multiple backpack turn 0 1 backpackFor the first currency the possible status is w[I] to cashState equation dp[j]=dp[j-c[i]]+w[i] (c[i] means "volume" is actually value equal to w[i] easy to distinguish) use count[i] to record the number of uses of the currency in the n[i] note before each entry into the inner loop (that is, the count is cleared before the currency change 0)
#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 backpack)

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.