// Eddy 继续

Problem Description
As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other hand, the dramatic fast increasing pace of the function caused the value of Ackermann function hard to calcuate.



Ackermann function can be defined recursively as follows:





Now Eddy Gives you two numbers: m and n, your task is to compute the value of A(m,n) .This is so easy problem,If you slove this problem,you will receive a prize(Eddy will invite you to hdu restaurant to have supper).
 
Input
Each line of the input will have two integers, namely m, n, where 0 < m < =3.

Note that when m<3, n can be any integer less than 1000000, while m=3, the value of n is restricted within 24. 

Input is terminated by end of file.
 
Output
For each value of m,n, print out the value of A(m,n).
 
Sample Input
  1. 1 3
  2. 2 4
 
Sample Output
  1. 5
  2. 11
 
Author
eddy
 
/********************

看到哦这个题的第一眼感觉像是递推,然后依据那个题目中的公式发现不太好找。就先写了一个递归。打表,然后。恩。找规律……

打表,这才是真正的打表啊……

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvZ3JheV8xNTY2/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast" alt="">

看到这个表,规律就不用我说了吧……

*************************/

Code:

  1. #include <iostream>
  2. #include <string.h>
  3. #include <stdio.h>
  4. using namespace std;
  5. int num[30];
  6. int main()
  7. {
  8. int i,j,n,m;
  9. num[0] = 5;
  10. for(i = 1;i<30;i++)
  11. num[i] = num[i-1]*2+3;
  12. while(cin>>m>>n&&m&&n)
  13. {
  14. if(m==1)
  15. printf("%d\n",n+2);
  16. if(m==2)
  17. printf("%d\n",2*n+3);
  18. if(m==3)
  19. printf("%d\n",num[n]);
  20. }
  21. return 0;
  22. }

hdu 1165 Eddy&#39;s research II(数学题,递推)的更多相关文章

  1. HDU1165: Eddy's research II(递推)

    题目:http://acm.hdu.edu.cn/showproblem.php?pid=1165 果断不擅长找规律啊,做这种题静不下心来. Ackermann function can be def ...

  2. HDU 1164 Eddy&#39;s research I【素数筛选法】

    思路:将输入的这个数分成n个素数的相乘的结果,用一个数组存储起来.之后再输出就能够了 Eddy's research I Time Limit: 2000/1000 MS (Java/Others)  ...

  3. HDU 1165 Eddy's research II(给出递归公式,然后找规律)

    - Eddy's research II Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64 ...

  4. HDU 5950 - Recursive sequence - [矩阵快速幂加速递推][2016ACM/ICPC亚洲区沈阳站 Problem C]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5950 Farmer John likes to play mathematics games with ...

  5. HDU 1165 Eddy's research II (找规律)

    题意:给定一个表达式,然后让你求表达式的值. 析:多写几个就会发现规律. 代码如下: #pragma comment(linker, "/STACK:1024000000,102400000 ...

  6. HDU 1165 Eddy's research II

    题意:已知,求A(m, n). 分析:根据样例模拟一下过程就可以找出递推关系. #include<cstdio> #include<cstring> #include<c ...

  7. hdu 1162 Eddy&#39;s picture (Kruskal算法,prim算法,最小生成树)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1162 [题目大意] 给你n个点的坐标,让你找到联通n个点的一种方法.保证联通的线路最短,典型的最小生成 ...

  8. HDU-1165-Eddy&#39;s research II

    这个事实上是一个递归题.题目非常easy.m的数非常小.分三种情况.算一下.就能够直接把公式算出来. 当然,也能够用dp做: #include<iostream> #include< ...

  9. hdu 1207 汉诺塔II (DP+递推)

    汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

随机推荐

  1. 负载均衡获得真实源IP的6种方法

    除了X-FORWARD-FOR,负载均衡中获得真实源IP的方法还有很多种. 本文抛砖引玉,主要介绍获得真实源IP的多种方法,而不是具体配置. 负载均衡获得真实IP的方法有很多种,将形成专题文章. 本文 ...

  2. python 飞机大战 实例

    飞机大战 #coding=utf-8 import pygame from pygame.locals import * import time import random class Base(ob ...

  3. Codeforces Round #198 (Div. 2)C,D题解

    接着是C,D的题解 C. Tourist Problem Iahub is a big fan of tourists. He wants to become a tourist himself, s ...

  4. java MD5加密的工具类

    import java.security.MessageDigest; /** * MD5加密工具类 * @author zwq */ public class MD5Util { /** * MD5 ...

  5. Linux od与hexdump命令

    od命令:以指定格式输出文件内容常用格式:od -Ax -tx1 filename直接格式:od filename 等价 od -o filename语法:od [-abcdfsiloxv] [-An ...

  6. 第十课: - 读取/写入Excel/Json格式数据

    第 10 课 从DataFrame到Excel 从Excel到DataFrame 从DataFrame到JSON 从JSON到DataFrame In [1]: import pandas as pd ...

  7. arttemplate.js简洁写法案例

    <!DOCTYPE html> <html> <head lang="en"> <meta charset="UTF-8&quo ...

  8. knockout.js(js)代码在IE中出现“意外地调用了方法或属性”的错误

    var CartListViewModel = function () { var self = this; self.payment = [ { name: "", value: ...

  9. Walking on the path of Redis --- Data structure

    废话开篇 相比于其他内存数据库,Redis最大的特点就是拥有丰富的数据结构, 经常被称为Date Structure Server.Redis支持的数据结构包含strings, hashes, lis ...

  10. easyui的datetimebox时间格式化详解

    今天公司让用easyui的datetimebox组件,而且还要让格式化成大家通用的那种,网上搜了很多,但差不多都是复制黏贴的,最后请教了下螃蟹. 感谢螃蟹抽空给做了个例子,现在拿出来和大家分享下,效果 ...