Skip to content

Instantly share code, notes, and snippets.

@defacto133
Last active January 6, 2016 21:32
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 defacto133/85226ee99eca19dea0ab to your computer and use it in GitHub Desktop.
Save defacto133/85226ee99eca19dea0ab to your computer and use it in GitHub Desktop.
def fib_n_step_aux(n, k, memo):
if k <= 0:
return 0
if k in [1, 2]:
return 1
if k not in memo:
res = 0
for i in range(1, n + 1):
res += fib_n_step_aux(n, k - i, memo)
memo[k] = res
return memo[k]
def fib_n_step(n, k):
return fib_n_step_aux(n, k, {})
def f(n, m):
return 2**n - fib_n_step(m, n + 2)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment