PKU 1276 Cash Machine

Source: Internet
Author: User

<span style= "color: #000099;" >/*cash machinetime limit:1000ms Memory limit:10000k total submissions:26604 accepted:9397 DescriptionA Bank Plan s to install a machine for cash withdrawal. The machine was able to deliver appropriate @ bills for a requested cash amount. The machine uses exactly N distinct bill denominations, say DK, K=1,n, and for each denomination DK The machine have a supp Ly of NK Bills.  For example, N=3, n1=10, d1=100, n2=4, d2=50, n3=5, d3=10 means the machine has a supply of ten bills of @100 each, 4 bills of @50 each, and 5 bills of @10 each. Call cash The requested amount of cash the machine should deliver and write a program that computes the maximum amount of Cash less than or equal to cash so can be effectively delivered according for the available bill supply of the machine. Notes: The symbol of the currency delivered by the. For instance, @ could stand for dollar, euro, pound etc. Inputthe program input was from standard input. Each data setIn the input stands for a particular transaction and have the Format:cash N N1 D1 n2 D2 ... nN DN where 0 <= cash <= 100000 is the amount of cash requested, 0 <=n <= are the number of bill denominations and 0 <= nk <= s the number of available bills for the DK denomination, 1 <= dk <=, k=1,n. White spaces can occur freely betwe En the numbers in the input. The input data is correct. Outputfor each set of data the program prints the result to the standard output on a separate line as shown in the example S below. Sample Input735 3 4 6 5 3 350633 4 6 1 5 0 1735 3 10Sample Output73563000hintt He first data set designates a transaction where the amount of cash requested is @735. The machine contains 3 bill denominations:4 bills of @125, 6 bills of @5, and 3 bills of @350. The machine can deliver the exact amount of requested cash. In the second case, the bill supply of the does not fit the exact amount OF Cash requested. The maximum cash that can was delivered is @630. Notice that there can is several possibilities to combine the bills of the machine for matching the delivered cash. In the third case, the machine was empty and no cash is delivered. In the fourth case the amount of cash requested are @0 and, therefore, the machine delivers no cash. Sourcesoutheastern Europe 2002pku 1276By ivi2014.7.1 Multiple backpack This problem from the beginning of the conversion to 01 Knapsack timeout, to the subsequent array open small execution error, and then to hyper memory, timeout,,, to the last night 1:40 AC , the process really hard * * #include <iostream> #include <stdio.h> #include <string.h>using namespace Std;int f[13];int p [13];bool dp[111113];int num=0;int n=0;   int main () {int temp,i;        while (scanf ("%d%d", &num,&n)!=eof) {for (i=1;i<=n;i++) scanf ("%d%d", &f[i],&p[i]);        if (num==0) cout<< "0" <<endl;        else if (n==0) cout<< "0" <<endl;    else {memset (dp,0,num+3);    m=0;    Dp[0]=1; for (int k=1;k<=n;k++) for (int j=m;j>=0;j--) if (Dp[j]) {for (int i=1;i<=f[k];i++) {                        Temp=i*p[k]+j;                            if (temp<=num) {dp[temp]=1;                              if (temp>m) m=temp;         }}} Cout<<m<<endl;} } return 0;} </span>

Copyright notice: This article Bo Master original article. Blog, not reproduced without consent.

PKU 1276 Cash Machine

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.