Problem
阿克曼(Arkmann)函数 𝐴(𝑚,𝑛) 中,m与n的定义域是非负整数且本题中m<=3,n<=16。
函数的定义为:
 阿克曼函数
阿克曼函数
Solution
可以推出代码中的结论。
Code
| 12
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 
 | #include<cstdio>#include<iostream>
 #include<algorithm>
 #include <iomanip>
 #include<map>
 #include<cstring>
 #define io_opt ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
 #define ll long long
 using namespace std;
 ll akm(int m,int n){
 if(m==4&&n==0) return 13;
 if(m==0) return n+1;
 else if(m==1) return n+2;
 else if(m==2) return 2*n+3;
 else if(m==3) return ((1LL<<(n+3))-3);
 else if(m==4){
 return (1LL<<(akm(m,n-1)+3))-3;
 }
 cout<<"ERROR!"<<endl;
 while(1);
 }
 int m,n;
 int main(){
 io_opt;
 cin>>m>>n;
 cout<<akm(m,n)<<endl;
 return 0;
 }
 
 |