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).
Ackermann function can be defined recursively as follows:
![](https://i-blog.csdnimg.cn/blog_migrate/db6f693516cf674cd0fdd5ba7791fe35.png)
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.
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
分析:
告诉你m<=3,所以我们应该往这方面靠
看看m不同,是不是有不同的n的公式
纯粹找规律
。。。。。
根据递推公式
记忆化搜一下
打印m不同值 n相同值的结果出来
然后找规律。。。。
code:
#include <iostream> #include <cstdio> #include<stdio.h> #include<algorithm> #include<cstring> #include<math.h> #include<memory> #include<queue> #include<vector> using namespace std; int f(int n) { int s=1; for(int i=1;i<=n;i++) { s=s*2; } return s; } int slove(int m,int n) { if(m==0) return n+1; if(m==1) return n+2; if(m==2) return 2*n+3; if(m==3) return f(n+3)-3; } int main() { int n,m; while(~scanf("%d %d",&m,&n)) { printf("%d\n",slove(m,n)); } return 0; }