Skip to content

Instantly share code, notes, and snippets.

@itayB
Created September 25, 2016 14:24
Show Gist options
  • Save itayB/daf4347660f51e92956da704cfd4859b to your computer and use it in GitHub Desktop.
Save itayB/daf4347660f51e92956da704cfd4859b to your computer and use it in GitHub Desktop.
#include <iostream>
#include <map>
using namespace std;
int fib(int n) {
static map<int,int> mem{{1,1}, {0,1}};
if (mem.count(n) > 0) {
return mem[n];
}
int res = fib(n-1) + fib(n-2);
mem[n] = res;
return res;
}
int main() {
cout << fib(25) << endl;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment