Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int memo[105];
- int fib(int n) {
- if(n <= 2) {
- return 1;
- }
- if(memo[n] != -1) {
- return memo[n];
- }
- return memo[n] = fib(n - 1) + fib(n - 2);
- }
- int main() {
- int n;
- cin >> n;
- for(int i = 0; i <= n; i++) {
- memo[i] = -1;
- }
- cout << fib(n) << endl;
- return 0;
- }
- // fib(7) = fib(6) + fib(5)
- //
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement