12345678910111213141516171819202122
#include <iostream> #include <unordered_map> using namespace std; int fib(int n, unordered_map<int,int> memo) { if (memo.find(n) != memo.end()) return memo[n]; if(n <= 2) return 1; memo[n] = fib(n-1, memo) + fib(n-2, memo); return memo[n]; } int main() { cout << "What fibonacci number do you want?" << endl; int num; unordered_map<int,int> memoization; cin >> num; cout << fib(num, memoization) << endl; system("PAUSE"); }
int fib(int n, unordered_map<int,int> &memo)