We usually the following recurrence relation for the coin change problem:
(P
is the total money for which we need change and d_i
is the coin available)
But can't we make it like this:
(V
is the given sorted set of coins available, i
and j
are its subscripts with Vj
being the highest value coin given)
C[p,Vi,j] = C[p,Vi,j-1] if Vj > p
= C[p-Vj,Vi,j] + 1 if Vj <=p
Is there anything wrong with what I wrote? Though the solution is not dynamic but isn't it more efficient?
Vi
in your formula? – IVladVj
and you use commas to separate both indices and function parameters. I suggest using square brackets to make it clearer, I read your formula asC[p,(Vi),(j-1)]; C[(p-Vj),(Vi),(j)]
. – IVlad