博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
喵帕斯之天才算数少女
阅读量:3947 次
发布时间:2019-05-24

本文共 640 字,大约阅读时间需要 2 分钟。

喵帕斯之天才算数少女

Time Limit: 1000 ms Memory Limit: 65536 KiB

Problem 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/

你可能感兴趣的文章
Algorithm : Dijkstra's algorithm and Bellmon-Ford Paths algorithm
查看>>
Algorithm: k-nearest neighbors and decison boundary(Cross Validation)
查看>>
Algorithm: Principle Component Analysis for High Dimension Reduction Data
查看>>
Naive Bayesian for Text Classification (MLE, Gaussian Naive Bayesian)
查看>>
Algorithm: Decision Tree, Entropy, Information Gain and Continues features
查看>>
FastDFS 架构分析
查看>>
Windows 应用生成MiniDump文件的方法笔记
查看>>
安装FastDFS单机版环境
查看>>
动态规划-背包问题
查看>>
Windows10 + Nodejs调用C++语言Dll
查看>>
CSAPP - 一个简单的Shell
查看>>
《算法4》 Windows/Mac环境下使用Visual Studio Code和Orcale JDK1.8开发环境搭建
查看>>
精心整理很实用的前端笔记,看完你就在css上有很深的造诣了!!!
查看>>
前端开发在工作中用到的工具、软件、库.......------Sesiid
查看>>
正则表达式~~~很全的------Sestid
查看>>
在HTML中嵌入百度地图------Sestid
查看>>
Js或jQuery图片层叠轮播------Sestid
查看>>
js或jQuery实现返回顶部功能------Sestid
查看>>
JS实现拖拽效果------Sestid
查看>>
jQuery实现倒计时秒杀效果------Sestid
查看>>