Created
September 25, 2016 14:24
-
-
Save itayB/daf4347660f51e92956da704cfd4859b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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