Consider a problem in which you have a value N, and you need to calculate how many ways you can sum up to Ndollars using [1,2,5,10,20,50,100]Dollar accounts .
Consider the classic DP solution:
C = [1,2,5,10,20,50,100]
def comb(p):
if p==0:
return 1
c = 0
for x in C:
if x <= p:
c += comb(p-x)
return c
It does not introduce the order of the summed parts. For example, it comb(4)will give 5 results: [1,1,1,1],[2,1,1],[1,2,1],[1,1,2],[2,2]whereas in fact there are 3 results ( [2,1,1],[1,2,1],[1,1,2]all are the same).
What is the DP ID to calculate this problem? (non-elegant solutions, such as creating all possible solutions and removing duplicates, are not welcome)