设为首页 加入收藏

TOP

HDU1165:Eddy's research II
2015-11-21 01:18:48 来源: 作者: 【 】 浏览:5
Tags:HDU1165 Eddy' research

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

?

?

一道规律题

可以先写函数一个个数字打印出来,然后找规律

规律在代码中可见

?

[cpp]
#include ??
?
int main()?
{?
??? int n,m;?
??? __int64 a[30];?
??? int i;?
??? a[0] = 5;?
??? for(i = 1; i<=24; i++)?
??? {?
??????? a[i] = 2*a[i-1]+3;?
??? }?
??? while(~scanf("%d%d",&m,&n))?
??? {?
??????? if(m == 1)?
??????????? printf("%d\n",2+n);?
??????? else if(m == 2)?
??????????? printf("%d\n",3+2*n);?
??????? else if(m == 3)?
??????? printf("%I64d\n",a[n]);?
??????? }?
?
??? return 0;?
}?

#include

int main()
{
??? int n,m;
??? __int64 a[30];
??? int i;
??? a[0] = 5;
??? for(i = 1; i<=24; i++)
??? {
??????? a[i] = 2*a[i-1]+3;
??? }
??? while(~scanf("%d%d",&m,&n))
??? {
??????? if(m == 1)
??????????? printf("%d\n",2+n);
??????? else if(m == 2)
??????????? printf("%d\n",3+2*n);
??????? else if(m == 3)
??????? printf("%I64d\n",a[n]);
??????? }

??? return 0;
}

?

?

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇FatMouse's Speed 下一篇UVA 题目10010 - Where's Wal..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: