【搜索練習】【二】
阿新 • • 發佈:2017-06-28
std 技術分享 arc out gin load cnblogs view mes
提交: 135 解決: 91
[提交][狀態][討論版]
1617: 阿克曼函數(遞歸)
時間限制: 1 Sec 內存限制: 128 MB
提交: 135 解決: 91
[提交][狀態][討論版]
題目描述
阿克曼(
Ackmann)
函數
A(x,
y)
中,
x,
y
定義域是非負整數,
函數值定義為:
輸入
輸入兩個數,表示m和n。 兩個數均不超過10。
輸出
輸出一個數,表示結果(在longint範圍內 )
樣例輸入
1 1
樣例輸出
3
提示
來源
遞歸
幫助理解遞歸 按題目意思直接打就好
//不要抄錯題目條件不要問我怎麽知道的QAQ
#include<algorithm> #include<cstdio> #include<cstring> #include<iostream> #include<cmath> using namespace std; int x,y; long int ack(int m,int n) { if(m==0)return n+1; if(m!=0&&n==0)ack(m-1,1); if(m!=0&&n!=0)ack(m-1View Code,ack(m,n-1)); } int main() { cin>>x>>y; cout<<ack(x,y); puts(""); return 0; }
【搜索練習】【二】