We have n stamps where each stamp i has a specific denomination d(i) and size s(i). All denominations are distinct and we can use stamp denominations multiple times. Now I want to design an algorithm that with given d(i) and s(i) for stamps and a postage amount p, find the minimum total size of stamps that whose denominations will add to exactly p?
I know that it is a dynamic programming problem and also I feel that it is to be solved like knapsack problem. But I am totally confused because here the minimum total size of stamp should add up to p. I came up with the following recurrence and I know that this is not gonna be true because it does not check if the total min size adds up to p:
M(p)=min{M(p-d(i))}+s(i),M(p-d(i))} for i from 1 to n
Also I do not know how to tabulate that(in order to write iterative version of dynammic prog).
My guess is that I have to have a 2-D array with dimensions p and d(i) and each cells fills with s(i).