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. The first line of input 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 to each set of data input m and n, with a row to output the corresponding K.
Sample input
17 3
Sample output
8
source [email protected]
Idea: A very classic topic, recursive, you can find the function between the law (very simple).
Recursive thinking: If the number of plates is larger than the number of apples, then there is nothing to say, the output can be, or continue to recursion until the number of plates is larger than the number of apples
This question is also the NOIP2014 popularization Group preliminary examination question Oh!
The code is as follows:
1#include <stdio.h>2 intFunintMintN)3 {4 if(m==0|| n==1)5 return 1; 6 if(n>m)7 returnFun (m,m);8 Else9 returnFun (m,n-1) +fun (M-n,n);Ten } One A intMain () - { - intK,m,n; thescanf"%d",&K); - while(k--) - { -scanf"%d%d",&m,&n); +printf"%d\n", Fun (m,n)); - } +}
Introduction to openjudge-Computing (A)-Putting apples