神奇的函数(使用C语言)
Time Limit: 1000 ms Memory Limit: 65536 KiB
Problem Description
神奇的函数是这样被定义的:
F(n, m) = {
if(n == 1 || m == 1)
F(n, m) = 1;
else
F(n, m) = F(n-1, m) + F(n, m-1);
}
Input
多组输入。
每组两个以空格分隔的整数 n, m (1 <= n, m <= 10)。
Output
对于每组数据,输出一个整数表示 F(n, m) 的值。
Sample Input
1 2
Sample Output
1
Hint
Source
【2016级《程序设计基础(B)II》期末上机考试-补测】UMR
#include <stdio.h>
#include <stdlib.h>
int f(int n,int m)
{
if(n==1||m==1) return 1;
else return f(n-1,m)+f(n,m-1);
}
int main()
{
int n,m;
while(~scanf("%d %d",&n,&m))
{
f(n,m);
printf("%d\n",f(n,m));
}
return 0;
}