Advertisement
viligen

binomial_coeff_DP

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