为啥全mle??????

B2144 阿克曼(Ackermann)函数

两个判断弄反了,应该前面的是 `s==0`,后面的是 `d==0`
by jqQt0220 @ 2023-10-06 20:31:41


你好像d==0和s==0的返回值错了 应该是如下: ``` #include <bits/stdc++.h> using namespace std; int akm(int s, int d) { if(s == 0) { return d+1; } if(d == 0) { return akm(s - 1,1); } return akm(s-1,akm(s,d-1)); } int main() { int n, m; cin >> n >> m; cout << akm(n, m); } ```
by hytallenxu @ 2023-10-06 20:32:02


if里面的s和d写反了导致递归函数一直无法结束,爆栈了 AC代码: ```cpp #include <bits/stdc++.h> using namespace std; int akm(int s, int d) { if(s == 0) { return d+1; } if(d == 0) { return akm(s - 1,1); } return akm(s-1,akm(s,d-1)); } int main() { int n, m; cin >> n >> m; cout << akm(n, m); } ```
by susenyang @ 2023-10-06 20:32:27


@[autowaer](/user/855039) az
by hytallenxu @ 2023-10-06 20:32:56


@[hytallenxu](/user/726098) 比我快一步orz
by susenyang @ 2023-10-06 20:53:44


|