Advertisement
Guest User

Untitled

a guest
Aug 23rd, 2019
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.25 KB | None | 0 0
  1. // f(0) = 0, f(1) = 1 f(x) = f(x-1) + f(x-2)
  2. int fibonacci(int n) {
  3. static vector<int> results(31, 0);
  4. if (n <= 1) return n;
  5. if (results[n] != 0) return results[n];
  6. results[n] = fibonacci(n-1) + fibonacci(n-2);
  7. return results[n];
  8. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement