Guest User

Untitled

a guest
Jan 23rd, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. a = [1,4,5,10]
  2. cache = {}
  3. for i in a:
  4. cache[i] = 1
  5.  
  6. counter = 0
  7. def coin(x):
  8. if not x in cache:
  9. tmp = []
  10. for i in a:
  11. if (x-i) > 0:
  12. if (x-i) in cache:
  13. tmp.append(1+cache[x-i])
  14. else:
  15. tmp.append(1+coin(x-i))
  16. cache[x] = min(tmp)
  17. return cache[x]
  18. else:
  19. return cache[x]
Add Comment
Please, Sign In to add comment