51Nod 2656 阿克曼函数

Problem

阿克曼(Arkmann)函数 𝐴(𝑚,𝑛) 中,m与n的定义域是非负整数且本题中m<=3,n<=16。

函数的定义为:

阿克曼函数

Solution

可以推出代码中的结论。

Code

#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;
}
posted @ 2019-09-08 21:51  CCWUCMCTS  阅读(409)  评论(0编辑  收藏  举报