#include <iostream>
#include <string.h>
#include <stdio.h>
#include <string>
#include <stack>
#include <algorithm>
#include <math.h>
using namespace std;
int fun(int m,int n)//m apple n plate
{
if(m==0||n==1)
return 1;//针对m和n都有递归出口
else if(n>m)
return fun(m,m);//当盘子个数比苹果个数多时,结果相当于盘子个数与苹果个数一样多的情况
else
return fun(m,n-1)+fun(m-n,n);//情况分为没有盘子是空的和至少有一个盘子是空的
}
int main()
{
int t;
cin >> t;
while(t--)
{
int p,q;
cin >> p>>q;
cout<<fun(p,q)<<endl;
}
return 0;
}
递归之放苹果
最新推荐文章于 2022-03-18 20:47:33 发布