I was solving following problem.
and its solution algorithm is at http://www.algorithmist.com/index.php/UVa_11517
pseudo alogorithm
int dp[30001];
dp[0] = 0;
for (int i=1; i<=30000; i++)
dp[i] = INFINITE;
for each coin C do
for (int v = 30001 - C - 1; v >= 0; v--)
if (dp[v] < INFINITE)
dp[v+C] = min(dp[v+C], dp[v]+1);
But I think that its solution is wrong.
Lets take case where coin denomination are :
Coins = [500,1000,1500]
and for price = 3000, According to above solution its answer would be 3000 with 3 coins. But 3000 can be obtain from 2 coins of 1500.
Please let me know whether this solution is wrong or right.
Aucun commentaire:
Enregistrer un commentaire