CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#include <iostream>
#include <map>
using namespace std;
static map<int,int>memo{};
int q(int n){
if(n<=2)
return 1;
auto p = memo.emplace(n,0);
if(p.second)
p.first->second =
(q(n-(q(n-1)))+q(n-(q(n-2))));
return p.first->second;
}
int main(){
int n;
cin>>n;
cout<<"q("<<n<<") = "<<q(n)<<'\n';
//104789 max for me.
}
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run