http://poj.org/problem?id=1664
放苹果
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 23149 | Accepted: 14694 |
Description
把M个同样的苹果放在N个同样的盘子里,允许有的盘子空着不放,问共有多少种不同的分法?(用K表示)5,1,1和1,5,1 是同一种分法。
Input
第一行是测试数据的数目t(0 <= t <= 20)。以下每行均包含二个整数M和N,以空格分开。1<=M,N<=10。
Output
对输入的每组数据M和N,用一行输出相应的K。
Sample Input
1 7 3
Sample Output
8
Source
#include<stdio.h>
int f(int a,int b)
{
if(a==0||b==1) return 1;
if(a<b) return f(a,a);
return f(a,b-1)+f(a-b,b);
}
int main()
{
int n;
scanf("%d",&n);
while(n--)
{
int a,b;
scanf("%d%d",&a,&b);
printf("%d\n",f(a,b));
}
return 0;
}
欢迎大家积极留言,欢迎喜欢acm的战友 以及喜欢编程的同志 同学 加我qq:827552788