View Code of Problem 787

#include<stdio.h>
#include<string.h>
int apple(int m,int n){
	if(m==0||n==1)       //碟子1个 苹果无都只有一种分法 
		return 1;
	if(n>m)               //碟子>苹果
		return apple(m,m);
	else
		return apple(m,n-1) + apple(m-n,n);         //共有两种方案  有0与无0 有零则减少一个盘子
		//无0则每个盘子减1
}
int main(){
	int t;
	while(scanf("%d",&t)!=EOF){
		while(t--){
			int m,n;         //m苹果 n碟子 
			scanf("%d %d",&m,&n);
			printf("%d\n",apple(m,n));
		}
	}
	return 0;
}

Double click to view unformatted code.


Back to problem 787