以下C++代码的运行结果是?
#include <iostream>
#include <vector>
using namespace std;
vector<int> memo;
int f(int n) {
if(n <= 1) return n;
if(memo[n] != -1) return memo[n];
memo[n] = f(n-1) + f(n-2);
return memo[n];
}
int main() {
int n = 5;
memo.resize(n+1, -1);
cout << f(n) << endl;
return 0;
}
正在加载题目数据…
子题
该题型需在试卷/作业中作答,单题练习暂不支持
答案解析