hdu 1165 Eddy's research II(数学题,递推)

// 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 3
2 4

Sample Output

5
11

Author

eddy

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

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

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

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

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

Code:

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int num[30];
int main()
{
    int i,j,n,m;
    num[0] = 5;
    for(i = 1;i<30;i++)
        num[i] = num[i-1]*2+3;
    while(cin>>m>>n&&m&&n)
    {
        if(m==1)
            printf("%d\n",n+2);
        if(m==2)
            printf("%d\n",2*n+3);
        if(m==3)
            printf("%d\n",num[n]);
    }
    return 0;
}

hdu 1165 Eddy's research II(数学题,递推),布布扣,bubuko.com

hdu 1165 Eddy's research II(数学题,递推)

时间: 2024-10-20 22:54:09

hdu 1165 Eddy's research II(数学题,递推)的相关文章

HDU 1165 Eddy&#39;s research II(递推)

坑了我好久,乍看很简单,记忆化搜索结果爆栈,然后改成递推之后WA . 后来发现,是在计算m=3的数据时出现了错误,因为当m=3时,即使n很小,结果也会很大,所以无法利用m=2时的结果递推,要怎么办呢?  将m=2的结果打印出来可以发现这是一个等差数列,通项为S(n) = 2*n + 3; 这有什么用呢? 我们可以发现,当 m=3时由递推式可以写成A(m,n) = A(2,A(m,n-1)) = 2*A(m,n-1) + 3; 所以只要知道了A(3,0),我们就能递推出所有m=3时的值了 . 细节

HDU 1165 Eddy&#39;s research II

Eddy's research II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3970    Accepted Submission(s): 1459 Problem Description As is known, Ackermann function plays an important role in the sphere

HDU 1165 Eddy&#39;s research II (推公式)

Eddy's research II Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3122    Accepted Submission(s): 1137 Problem Description As is known, Ackermann function plays an important role in the sphere

HDU 1165 Eddy&#39;s research II(给出递归公式,然后找规律)

- Eddy's research II Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Description As is known, Ackermann function plays an important role in the sphere of theoretical computer science. However, in the other h

HDU1165: Eddy&#39;s research II(递推)

题目:http://acm.hdu.edu.cn/showproblem.php?pid=1165 果断不擅长找规律啊,做这种题静不下心来. Ackermann function can be defined recursively as follows: 递推如上图, 0<m<=3,0<=n<=1000000,,当m==3时,n>=0&&n<=24. 首先发现a(0,i)=i+1; 另外n==0时,a(1,0)=a(0,1)=2; 当m==1,n>

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

汉诺塔II Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 4529    Accepted Submission(s): 2231 Problem Description 经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往

HDU 1207 汉诺塔II (递推)

经典的汉诺塔问题经常作为一个递归的经典例题存在.可能有人并不知道汉诺塔问题的典故.汉诺塔来源于印度传说的一个故事,上帝创造世界时作了三根金刚石柱子,在一根柱子上从下往上按大小顺序摞着64片黄金圆盘.上帝命令婆罗门把圆盘从下面开始按大小顺序重新摆放在另一根柱子上.并且规定,在小圆盘上不能放大圆盘,在三根柱子之间一回只能移动一个圆盘.有预言说,这件事完成时宇宙会在一瞬间闪电式毁灭.也有人相信婆罗门至今仍在一刻不停地搬动着圆盘.恩,当然这个传说并不可信,如今汉诺塔更多的是作为一个玩具存在.Gardon

hdu 1165 Eddy&amp;#39;s research II(数学题,递推)

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

杭电 HDU 1164 Eddy&#39;s research I

Eddy's research I Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7117    Accepted Submission(s): 4268 Problem Description Eddy's interest is very extensive, recently  he is interested in prime