您的位置:首页 > 其它

HDU 1165 Eddy's research II

2016-06-15 22:45 447 查看


Eddy's research II

Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 4141    Accepted Submission(s): 1545


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

 

Recommend

JGShining   |   We have carefully selected several similar problems for you:  1158 1159 1114 1074 1208 
思路:直接算,超时了,那就找规律呗。推规律,真麻烦,算着算着把自己算晕了。


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int a[5][110000],i,j,k,l,m,n;
//int dfs(int m,int n)利用这个找出一部分值,便于找规律。
//{
//	if(m==0)
//    return n+1;
//	if(m>0&&n==0)
//	return dfs(m-1,1);
//	if(m>0&&n>0)
//	return dfs(m-1,dfs(m,n-1));
//}
void init()
{
a[3][0]=5;
for(i=0;i<110000;i++)
{
a[0][i]=i+1;
a[1][i]=i+2;
a[2][i]=2*i+3;
}
for(i=1;i<=24;i++)
a[3][i]=a[3][i-1]*2+3;
}
int main()
{
init();
while(scanf("%d%d",&m,&n)!=EOF)
{
//printf("%d\n",dfs(m,n));
printf("%d\n",a[m]
);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: