Advertisement
viligen

fib_DP

Aug 10th, 2022
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.24 KB | None | 0 0
  1. def fib_calc(n, memo):
  2.     if n in memo:
  3.         return memo[n]
  4.     if n <= 2:
  5.         return 1
  6.     result = fib_calc(n-1, memo) + fib_calc(n-2, memo)
  7.     memo[n] = result
  8.     return result
  9.  
  10.  
  11. n = int(input())
  12.  
  13.  
  14. print(fib_calc(n, {}))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement