Let be the minimum number of stamps for total . Since denomination 1 is available, every nonnegative total is reachable. The dynamic programming recurrence is
Fill the table in increasing order of :
F[0] = 0
for x = 1,...,m:
    F[x] = infinity
    for i = 1,...,n:
        if d[i] <= x:
            F[x] = min(F[x], 1 + F[x-d[i]])
return F[m]
Every representation of has a last stamp , so its remaining count is at least . Conversely, appending to an optimal residual representation attains each candidate. Thus the recurrence is exact by the principle of optimality. Worst-case time is , with storage. This is pseudo-polynomial time in the numerical target, rather than polynomial time in its binary encoding length.

Articles by others on the same topic (0)

There are currently no matching articles.