Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- a = [1,4,5,10]
- cache = {}
- for i in a:
- cache[i] = 1
- counter = 0
- def coin(x):
- if not x in cache:
- tmp = []
- for i in a:
- if (x-i) > 0:
- if (x-i) in cache:
- tmp.append(1+cache[x-i])
- else:
- tmp.append(1+coin(x-i))
- cache[x] = min(tmp)
- return cache[x]
- else:
- return cache[x]
Add Comment
Please, Sign In to add comment