Skip to content

Instantly share code, notes, and snippets.

@niklasb
Created September 29, 2015 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklasb/e350e694f50bea76ec61 to your computer and use it in GitHub Desktop.
Save niklasb/e350e694f50bea76ec61 to your computer and use it in GitHub Desktop.
memo = {}
def p(n,k):
if (n,k) in memo: return memo[n,k]
if (n,k) == (0,0): return 1
if n < k or (n > 0 and k == 0): return 0
memo[n,k] = p(n-k,k) + p(n-1,k-1)
return memo[n,k]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment