Suppose my job is to buy a certain number of objects - W for a certain amount of money - $B. Objects come in N different varieties and the cost of one object of variety i is Ci. For example if there are N = 4 varieties of objects whose costs are C1 = 3, C2 = 4, C3 = 7, C4 = 18 and I have B = $20 with which to buy exactly W = 5 objects, then I could buy one $7 object, one $4 object and three $3 objects.
I want an algorithm to solve this problem. Can anyone provide me such an algorithm preferably if possible using Dynamic programming approach.