View Code of Problem 787

#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
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;
}
/*
Main.cc:3:24: bits/stdc++.h: No such file or directory
Main.cc: In function `int main()':
Main.cc:20: error: `cin' undeclared (first use this function)
Main.cc:20: error: (Each undeclared identifier is reported only once for each function it appears in.)
Main.cc:24: error: `cout' undeclared (first use this function)
Main.cc:24: error: `endl' undeclared (first use this function)
*/

Double click to view unformatted code.


Back to problem 787