阿克曼(Ackermann)函数
生活随笔
收集整理的這篇文章主要介紹了
阿克曼(Ackermann)函数
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
阿克曼函數定義如下:
?
#include<iostream> #include<vector> using namespace std; int A(int m, int n) {cout << m << ',' << n << endl;if (m == 0)return n + 1;else if (m > 0 && n == 0)return A(m - 1, 1);elsereturn A(m - 1, A(m, n - 1)); } int main() {int m = 4, n = 1;//cout<<A(m, n); //爆棧vector<int> val(m + 1, -1), index(m + 1, -1);index[0] = 0; val[0] = 1;while (index[m] < n) {val[0]++;index[0]++;for (int j = 1; j <= m; j++) {if (index[j - 1] == 1) {val[j] = val[j - 1];index[j] = 0;}if (val[j] != index[j - 1])break;index[j]++;val[j] = val[j - 1];}}return val[m];return 0; }?
總結
以上是生活随笔為你收集整理的阿克曼(Ackermann)函数的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 200 元人民币面世!
- 下一篇: JAVA王思聪吃热狗程序_王思聪吃热狗小