Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "stdafx.h"
- #include <iostream>
- #include <map>
- __int64 fib(int n, std::map<int, __int64> &memo) {
- if (!memo.count(n)) {
- memo[n] = fib(n-1, memo) + fib(n-2, memo);
- }
- return memo.at(n);
- }
- int _tmain(int argc, _TCHAR* argv[])
- {
- std::map<int, __int64> memo;
- memo[0] = 0;
- memo[1] = 1;
- for(int i=0; i < 100; i++) {
- std::cout << fib(i, memo) << " ";
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement