PKU 1276 Cash Machine

Source: Internet
Author: User

<Span style = "color: #000099;">/* Cash MachineTime Limit: 1000 MS Memory Limit: 10000 K Total Submissions: 26604 Accepted: 9397 DescriptionA Bank plans to install a machine for cash withdrawal. the machine is 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 has a supply of nk B Ills. for example, N = 3, n1 = 10, D1 = 100, n2 = 4, D2 = 50, n3 = 5, d3 = 10 means the machine has a supply of 10 bills of @ 100 each, 4 bills of @ 50 each, and 5 bills of @ 10 each. call cash the requested amount of cash the machine shocould deliver and write a program that computes the maximum amount of cash less than or equal to cash that can be specified tively delivered according to the available bill supply the Machine. notes: @ is the symbol of the currency delivered by the machine. for instance, @ may stand for dollar, euro, pound etc. inputThe program input is from standard input. each data set in the input stands for a participant transaction and has the format: cash N n1 D1 n2 D2... nN DN where 0 <= cash <= 100000 is the amount of cash requested, 0 <= N <= 10 is the number of bill denominations and 0 <= nk <= 1000 is the number of available bills for the Dk denomination, 1 <= Dk <= 1000, k = 1, N. white spaces can occur freely between the numbers in the input. the input data are correct. outputFor each set of data the program prints the result to the standard output on a separate line as shown in the examples below. sample Input735 3 4 125 6 5 3 350633 4 500 30 6 100 1 5 0 1735 00 3 10 100 10 5 0 10 10 Sample Output73563000HintThe 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 machine does not fit the exact amount of cash requested. the maximum cash that can Yes delivered is @ 630. notice that there can be several possibilities to combine the bills in the machine for matching the delivered cash. in the third case the machine is empty and no cash is delivered. in the fourth case the amount of cash requested is @ 0 and, therefore, the machine delivers no cash. sourceSoutheastern Europe 2002pku 1276By ivi2014.7.1 multiple backpacks this question was converted from the first to the 01 backpack timeout, to the later array opening a small runtime error, then to the super memory ,, Time-out, and the last night at AC, the process is really hard */# include <iostream> # include <stdio. h> # include <string. h> using namespace std; int f [13]; int p [13]; bool dp [1, 111113]; int num = 0; int n = 0; int main () {int temp, I; while (scanf ("% d", & num, & n )! = EOF) {for (I = 1; I <= n; I ++) scanf ("% 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>

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.