View Code of Problem 787

#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
int func(int m, int n) {
	if(m==0){//没有苹果了,只有1中放法0,0,0,0,0……
		return 1;
	}
	if (n == 0) {//没有盘子,0种放法
		return 0;
	}
	if (m < n) {//假设3个苹果放到7个盘子里,其实只要求3个苹果放在3个盘子里的放法
		return func(m, m);
	}
	return func(m, n - 1) + func(m - n, n);//m个苹果放到n个盘子里的放法=空一个盘子的放法+不空盘子的放法
}
int main()
{
	int t;
	cin >> t;
	while (t--) {
		int m, n;
		cin >> m >> n;
		cout << func(m, n) << endl;
	}

	return 0;
}

Double click to view unformatted code.


Back to problem 787