Skip to content

Instantly share code, notes, and snippets.

@mattliving
Created June 3, 2012 19:09
Show Gist options
  • Save mattliving/2864671 to your computer and use it in GitHub Desktop.
Save mattliving/2864671 to your computer and use it in GitHub Desktop.
Simple Dynamic Programming in Python
def main():
coins = [1, 3, 5]
S = 11
M = [946958486]*(S+1)
M[0] = 0
print M
for i in range(1, S+1):
for j in range(0, len(coins)):
if coins[j] <= i and M[i-coins[j]]+1 < M[i]:
M[i] = M[i-coins[j]]+1
print M
return M[S]
print main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment