Branch pear

Title description

zzq likes to eat pears very much, and one day he got a basket of pears from ACMCLUB. Because he was more righteous, he planned to distribute the pears to his friends. Now he wants to put M pears on N plates (we allow some plates to be empty), can you tell how many divisions zzq has? (Please note, for example, there are three plates, we regard 5,1,1 and 1,1,5 as the same division)

Input The
input contains multiple sets of test samples. The first line of each input is an integer t.
In the next t line, enter two integers M and N in each line, which means there are M pears and N plates. (M and N are both greater than or equal to 0)

Output
For each pair of input M and N, how many ways are there to output.

Sample input
1
7 3

Sample output
8

Implementation code


```c
#include<bits/stdc++.h>
using namespace std;
int f(int m,int n)
{
    
    
	if(m==0||n==1)//当盘子一个只有一种分法 
	return 1;
	if(m>=n)//当梨大于盘子数 则有两种分法,即每个盘子一个都不为空和只有一个盘子为空. 
	return f(m-n,n)+f(m,n-1);
	//当梨小于盘子数,则剩余的盘子全部没用,去掉。 
	return f(m,m);
}
int main()
{
    
    
	int n,m,t,i,j;
	while(scanf("%d",&t)!=EOF)
	{
    
    
		while(t--)
		{
    
    
			scanf("%d%d",&m,&n);
			printf("%d\n",f(m,n));
		}
	}
	
}

Guess you like

Origin blog.csdn.net/m0_46381590/article/details/111416209