(1)斐波那契数列用记忆化搜索方式求解。
(2)代码:
#include<iostream>
using namespace std;
const int MAX_N=1e3+6;
int n,memo[MAX_N];
int fib(int n){
if(n<=1)return n;
if(memo[n]!=0)return memo[n];
return memo[n]=fib(n-1)+fib(n-2);
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);
cin>>n;
cout<<fib(n)<<endl;
}