Problem: 147. Dollars
New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up in 4 ways: 1x20c, 2 x10c, 10c+2 x5c, and 4 x5c.
Input
Input will consist of a series of real numbers no greater than $300.00 each on a separate line. Each amount will be valid, that is will be a multiple of 5c. The file will be terminated by a line containing zero (0.00).
Output
Output will consist of a line for each of the amounts in the input, each line consisting of the amount of money (with two decimal places and right justified in a field of width 6), followed by the number of ways in which that amount may be made up, right justified in a field of width 17.
Sample input
Sample output
Description of the Solution:
Let, constraint set={50,25,10,5,1}
make : 10 how many way
c=50 ; j=50 ; 50<=10 false; No loop// now way to make 10 by 50
c=25 ; j=25 ; 25<=10 false ; No loop// now way to make 10 by 50
c=10; j=10 ; 10<=10 true : now loop //have way to make 10
j=10; a[10]=a[10]+a[10-10]=a[10]+a[0]=0+1=1 // Globally a[10]=0; initaialize a[0]=1
j=11 ; 11<=10 break;
c=5 ; j=5 ; 5<=10 true ; loop
j=5; a[5]=a[5]+a[5-5]=a[5]+a[0]=0+1=1;//that mean only 5 make 5 one time
j=6 ; a[6]=a[6]+a[6-5]=a[6]+a[1]=0+0=0;
j=7,8,9 a[7]=a[8]=a[9]=0
j=10 ; a[10]=a[10]+1[10-5]=a[10]+a[5]=1+1=2
j=11 ; 11<=10 break;
c=1; j=1; j<=10 true ;loop
j=1; a[1]=a[1]+a[0]=1
j=2; a[2]=a[2]+a[1]=1
j=3,4 a[3]=a[4]=1
j=5; a[5]=a[5]+a[4]=1+1=2
j=6,7,8,9 ;a[6]=a[7]=a[8]=a[9]=2
j=10 ; a[10]=a[10]+a[9]=2+2=4;
j=11 ; 11<=10 break;
break;
a[10]=4 ;so 4 way to make 10 by {50,25,10,5,1}
Basic Code:
Code In C/C++ for the above problem:
New Zealand currency consists of $100, $50, $20, $10, and $5 notes and $2, $1, 50c, 20c, 10c and 5c coins. Write a program that will determine, for any given amount, in how many ways that amount may be made up. Changing the order of listing does not increase the count. Thus 20c may be made up in 4 ways: 1x20c, 2 x10c, 10c+2 x5c, and 4 x5c.
Input
Input will consist of a series of real numbers no greater than $300.00 each on a separate line. Each amount will be valid, that is will be a multiple of 5c. The file will be terminated by a line containing zero (0.00).
Output
Output will consist of a line for each of the amounts in the input, each line consisting of the amount of money (with two decimal places and right justified in a field of width 6), followed by the number of ways in which that amount may be made up, right justified in a field of width 17.
Sample input
0.20 2.00 0.00
Sample output
0.20 4 2.00 293
Description of the Solution:
Let, constraint set={50,25,10,5,1}
make : 10 how many way
c=50 ; j=50 ; 50<=10 false; No loop// now way to make 10 by 50
c=25 ; j=25 ; 25<=10 false ; No loop// now way to make 10 by 50
c=10; j=10 ; 10<=10 true : now loop //have way to make 10
j=10; a[10]=a[10]+a[10-10]=a[10]+a[0]=0+1=1 // Globally a[10]=0; initaialize a[0]=1
j=11 ; 11<=10 break;
c=5 ; j=5 ; 5<=10 true ; loop
j=5; a[5]=a[5]+a[5-5]=a[5]+a[0]=0+1=1;//that mean only 5 make 5 one time
j=6 ; a[6]=a[6]+a[6-5]=a[6]+a[1]=0+0=0;
j=7,8,9 a[7]=a[8]=a[9]=0
j=10 ; a[10]=a[10]+1[10-5]=a[10]+a[5]=1+1=2
j=11 ; 11<=10 break;
c=1; j=1; j<=10 true ;loop
j=1; a[1]=a[1]+a[0]=1
j=2; a[2]=a[2]+a[1]=1
j=3,4 a[3]=a[4]=1
j=5; a[5]=a[5]+a[4]=1+1=2
j=6,7,8,9 ;a[6]=a[7]=a[8]=a[9]=2
j=10 ; a[10]=a[10]+a[9]=2+2=4;
j=11 ; 11<=10 break;
break;
a[10]=4 ;so 4 way to make 10 by {50,25,10,5,1}
Basic Code:
Code In C/C++ for the above problem:
No comments:
Post a Comment