Home > Back-end >  Change problem (blue bridge Java)
Change problem (blue bridge Java)

Time:10-26

The bus price
Bus fares for 5 Angle, assuming that each passenger holds only two kinds of value of currency: 5 Angle, 1 yuan,
Suppose holding five Angle of passengers have m people, hold 1 yuan passengers have n people, in the beginning, due to special circumstances, the conductor had no change can be find,
We want to know the m + n passengers buy tickets in what order can be smoothly to complete process,
Obviously, m & lt; N, could not finish, m & gt;=n, in some cases, for example, the first ticket passengers can hold 1 yuan,
The following program to calculate the m + n passengers all possible smoothly to complete the number of the combination of the different situation,
Note: only CARES about 5 angles and different arrangement of the order of the 1 yuan appear alternately, hold the same value of two passengers to exchange the position is not exactly a new situation to count,
Given the code is as follows: online
The
reference
public class bus fares {
//m: hold the number of five Angle of currency
//n: hold the number of 1 yuan coin
//return: all types of the smooth completion of process the ticket order ticket number

Public static int f (int m, int n) {
If (m & lt; N)
return 0;
If (n==0)
return 1;
The return of f (m - 1, n) + f (m, n - 1); Fill in the blanks//
}
Public static void main (String [] args) {
System. The out. Println (f (10, 8));
}
}

I have a question:
If according to this method, for example, 1555 (1 represents a RMB 5 cents) this is also counted as reasonable as (5551) is that even if do not reasonable