Skip to content

Instantly share code, notes, and snippets.

@laalaguer
Created January 19, 2022 05:53
Show Gist options
  • Save laalaguer/38f89e14b9778b45d384cda9319b0d25 to your computer and use it in GitHub Desktop.
Save laalaguer/38f89e14b9778b45d384cda9319b0d25 to your computer and use it in GitHub Desktop.
# No speed up.
def f(n):
if n == 1:
print('n==1, directly return 1')
return 1
p = [] # Storage for temp results.
for i in range(1, n): # i in [1, n)
temp = 1 + max(i-1, f(n-i))
p.append(temp)
return min(p)
print('f(100)', f(100))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment