本文共 640 字,大约阅读时间需要 2 分钟。
喵帕斯之天才算数少女
Time Limit: 1000 ms Memory Limit: 65536 KiBProblem Description
莲酱要上一年级了,但是老师给他出了一个特别难的算术题。
老师给出了一个函数
F(m, n)的定义是:
若m=0,返回n+1。
若m>0且n=0,返回F(m-1,1)。
若m>0且n>0,返回F(m-1,F(m,n-1))。
给出 m 和 n,计算 F(m, n) 的值。
Input
多组输入直到EOF结束。(数据组数小于 10)每组数据输入一行,包含两个非负整数 m,n。(0 <= m <= 3, 0 <= n <= 10)
Output
每组数据输出一行,为 F(m, n) 的答案Sample Input
3 2 3 10 2 1 Sample Output 29 8189 5代码如下:
#include#include int f(int m,int n){ int y; if(m==0)y=n+1; else if(m>0&&n==0)y=f(m-1,1); else y=f(m-1,f(m,n-1)); return y;}int main(){ int n,m; while(~scanf("%d%d",&m,&n)) { printf("%d\n",f(m,n)); } return 0;}
转载地址:http://tzhwi.baihongyu.com/