cash = (200, 100, 50, 20, 10, 5, 2, 1) #cash = (5, 2, 1) total = [] def im(lis, x, n, a = 0): if a == len(cash) - 1: x.append(n) lis.append(x[:]) x.pop() return for i in xrange(int(n / cash[a]) + 1): x.append(i) im(lis, x, n - i * cash[a], a + 1) x.pop() im(total, [], 200) print len(total)