Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2017
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.41 KB | None | 0 0
  1. known={}
  2. def recur(coinlist, pence):
  3.     if len(coinlist)==1:
  4.         return 1
  5.     elif pence in known:
  6.         for i in known[pence]:
  7.             if i[0]==len(coinlist):
  8.                 return i[1]
  9.     x=0
  10.     for i in range(int(pence/coinlist[-1])+1):
  11.         x+=recur(coinlist[:-1],pence-i*coinlist[-1])
  12.     try:
  13.         known[pence].append([len(coinlist),x])
  14.     except:
  15.         known[pence]=[[len(coinlist),x]]
  16.     return x
  17. print(recur([1,2,5,10,20,50,100,200],200))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement