Title Source: NYOJ176
Problem Description:
Divide a positive integer m into n positive integers, how many methods are there?
Example: The sum of 5 is divided into 3 positive positive numbers, there are two kinds of methods:
1 1 3
1 2 2
Input:
The first line is an integer t representing a common T-group test data (T<=50)
Each set of test data is a two positive integer m,n, where (1<=n<=m<=100) represents the number of positive integers to split and a positive integer to split.
Output:
Outputs the number of split methods for each group.
Analysis:
The topic can be replaced by the equivalent description: Put m the same Apple on n the same plate, do not allow some of the plate empty, ask how many different methods, where n plate is exactly equivalent?
Assuming that f (m,n) represents the method of placing m apples in n plates, the following recursive relationship can be obtained:
1, M < N, f (m,n) = 0, because the plate is not allowed to be empty;
2, M = N, f (m,n) = 1, in order to ensure that no plate empty, can only be placed on each plate;
3, M > N, first to each plate inside into 1 apples, and the remaining m-n Apple, the remaining m-n Apple can choose to put in 1, 2 ... n plates, so there are:
F (m,n) = f (m-n,1) + f (m-n,2) +......+f (m-n,n)
4. Initial conditions:
When N=1, f (m,n) = 1, that is, only m apples can be placed on this plate;
Code:
Recursive and recursive code can also be written according to the recursion above.
Recursive code See GitHub: Integer Division 2
Algorithm notes-integer Division 2