Get change. |
|
We know that the renminbi has 1, 2, 5, 10, 20, 50, 100 of these denominations. Now give you n (1≤n≤250) yuan, let you calculate for three ways to express 。 |
Topic Category: |
Cycle |
Difficulty: |
Primary |
Scores: |
|
Run time limit: |
Ten Sec |
Memory Limit: |
MByte |
Stage: |
Recruitment management |
input:
input has multiple groups, Each group of rows, for a consolidation N. The input ends with 0. |
output:
There are several representations of how to output this denomination. |
|
Sample output: |
13 |
There are only 7 denominations of change: 1,2,5,10,20,50,100; When you enter an n value between two denominations, such as n=25, then n is between 20 and 50, then the maximum value for the change is 20; using recursive thinking, the number of ways to change the money can be divided into two categories, a class of which contains 20 denominations, The other is not included 20, the use of the addition principle, the two categories can be added, and for these two classes may also continue to divide, for the inclusion of 20, then the face value at this time becomes n-20=5, for not including 20, then the face value of the maximum is 10, so recursion down;
The recursive type is: Find (n,i) =find (n-rmb[i],i) +find (n,i-1);
Where Rmb[]={1,2,5,10,20,50,100};,i is the subscript that points to the first rmb[i with a value less than or equal to n].
#include <iostream>using namespace std;/* */static int rmb[]={1,2,5,10,20,50,100};int find (int n,int i) {if (n <=1 | | Rmb[i]==1) return 1;return find (n-rmb[i],i) +find (n,i-1);} int main () {int n;int i;while (cin>>n && n!=0) {for (i=6;i>=0 && n<rmb[i];i--);cout<< Find (N,i) <<endl;} return 0;}
Huawei apply for test questions-Find change (recursive solution)