Put Apple
Description
Put M identical apples on N identical dishes, and some are allowed to leave them empty. How many different methods are there? (Expressed in K) 5, 1, 1, and 1, 5, 1 are the same method.
Input
The first line is the number of test data t (0 <= T <= 20 ). Each of the following lines contains two integers, M and N, separated by spaces. 1 <= m, n <= 10.
Output
Output the corresponding K in one row for each group of input data M and N.
Sample Input
17 3
Sample output
8
Source
Search for the given apple in sequence, and make statistics on the status that meets the conditions. You can.
CodeAs follows:
# Include < Stdio. h >
Int Total = 0 ;
Int M, n, h;
Void Solve ( Int X, Int K)
{
Int I, J;
If (H = 0 && K <= N)
{
Total++;
Return;
}
If (K = N) Return ;
Else
{
For (I = X; I > = 1 ; I -- )
{
If (I <= H)
{
H=H-I;
Solve (I, K+1);
H=H+I;
}
}
}
}
Main ()
{
Int Count;
Scanf ( " % D " , & Count );
While (Count -- )
{
Scanf ( " % D " , & M, & N );
H = M;
Total = 0 ;
Solve (m, 0 );
Printf ( " % D \ n " , Total );
}
}