CPP
cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int fcalls1=0, fcalls2=0, fcalls3=0;
int q(int n){
fcalls1++;
if(n<=2) return 1;
else return (q(n-(q(n-1)))+q(n-(q(n-2))));
}
static vector<int> mem1{};
int vq(int n){
fcalls2++;
if(n<=2) return 1;
else if((unsigned)n>=mem1.size()) mem1.resize(n+1);
else if(mem1[n]!=0) return mem1[n];
int res = (vq(n-(vq(n-1)))+vq(n-(vq(n-2))));
mem1[n] = res;
return res;
}
static map<int,int>mem2{};
int hq(int n){
fcalls3++;
if(n<=2) return 1;
Enter to Rename, Shift+Enter to Preview
OUTPUT
Run