Advertisement
Guest User

Untitled

a guest
Feb 19th, 2021
80
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. big fib_with_memo(int n) {
  2.     static int most_recent_addition_index = 1;
  3.     static std::vector<big> mem = {0, 1};
  4.  
  5.     if (most_recent_addition_index < n) {
  6.         big val = fib_with_memo(n-1) + fib_with_memo(n-2);
  7.         mem.push_back(val);
  8.         most_recent_addition_index++;
  9.  
  10.         return val;
  11.     }
  12.     return mem[n];
  13.  
  14. }
Advertisement
RAW Paste Data Copied
Advertisement