Describe
Put m the same apples on n the same plate, allow some plates to be empty, ask how many different ways?
(denoted by k) 5,1,1 and 1,5,1 are the same kind of sub-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 a space. 1<=m,n<=10.
Output
For each set of data entered M and N, the corresponding k is output in one line.
Sample input
1
3 ·
Sample output
8
I think
This problem is done with recursive thinking, we need to be clear, it should have two parameters, one is the number of apples m, one is the number of plates N.
Then we divide the case according to the comparison between M and N, noting that its repetition condition.
1. When M>n (Apple more), each plate must have at least one apple, so we need to consider how to put m-n an apple into the N plate.
2. When m<n (plates are more), this is actually the equivalent of putting m apples into m-plates.
3. When the M=n (apples and plates are as long), we can divide each one into an apple, that is, 1 times, and the empty plate on the case.
My Code
#include <iostream>using namespacestd;intFuncintMintN) { if(n==0|| m==0){ return 0; } if(n==m) { return 1+func (m,n-1); } if(m<N) { returnfunc (m,m); } if(m>N) { returnFunc (m-n,n) +func (m,n-1); }}intMain () {intk=0; CIN>>K; while(k) {intn,m; CIN>>m>>N; cout<<func (m,n) <<Endl; K--; } return 0;}
My summary
Such topics should first determine the number of good parameters, and then find ways to identify the relationship between the parameters of the composition, thus to the answer.
(recursive) 666: Put the Apples