1032. Ackerman函数
Description
Ackerman函数定义为:
A(m, n) =
n + 1, m = 0
A(m - 1, 1), m ≠ 0, n = 0
A(m - 1, A(m, n - 1)), m ≠ 0, n ≠ 0
Input Format
仅一行,两个整数m, n ( 0≤m≤3,0≤n≤1000
).
Output Format
相应A(m, n)的值。
Sample Input
2 30
Sample Output
63
#include<iostream> using namespace std; int ackerman(int m,int n){ if(m==0){ return n+1; }else{ if(n==0){ return ackerman(m-1,1); } else{ return ackerman(m-1,ackerman(m,n-1)); } } } int main(){ int m,n; cin>>m>>n; cout<<ackerman(m,n); return 0; }