放苹果-递归


#include<iostream>
using namespace std;
int f(int m,int n) {
//边界
	if(n == 0)
		return 0;
	if(m == 0) //不放苹果时返回1,因为允许有空盘 
		return 1;
	
//递归
if(n > m)
		return f(m,m);

	return f(m,n-1)+f(m-n,n);//有盘子为空的放法+没有盘子为空的放法 
}
int main() {
	int t,n,m;
	cin >> t;
	while(t--) {
		cin >> m >> n;
		cout << f(m,n) << endl ;
	}

	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_37503890/article/details/87902374