Ackermann Function
Time Limit:5s |
Memory limit:32M |
Accepted Submit:231 |
Total Submit:658 |
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:
Given m and n, your task is to compute the value of A(m,n)
Input
Each line of the input will have a 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
Original: chenyan
|
完全就是找规律而已!!m=0时,就是1,2,3,4,5,6,7,8,9……n+1
m=1时,就是2,3,4,5,6,7,8,9……n+2
m=2时,就是3,5,7,9,11,13,15……2*n+3
m=3时,等于A(2, A(n-1));这个用循环,一下子就能得出来了A(n)= 2*A(n-1)+3;
相当简单,但是一开始因为没找到规律,想了很多无用功,哎!!
posted on 2008-11-22 21:42
我来我往 阅读(1139)
评论(0) 编辑 收藏 引用 所属分类:
acm