You will find this easier to do with the correct pseudo-code:

DPChange (M, c, d)

//

// Arguments

// ========

// M the amount of change to be made

// c and array containing the coin denominations (in no particular order)

// d the number of denominations (ie the number of elements of c)

//

// Local Variables

// ===========

//

// bestNumCoins[0..M] array containing the optimal number of coins

//

....bestNumCoins(m) to make make change m. At end of processing

//

....bestNumCoin(M) will contain the minimum number of coins to

//

....make change for M

// i index for loop over the coin denominations

// m index for loop over amounts to make change for from 0 to M

//

1 bestNumCoins_0 <-- 0

2 for m <-- 1 to M

3

............bestNumCoins_m <-- infinity

4

............for i <-- 1 to d

//

// this next section computes min( bestNumCoins(m), bestNumCoins(m-c(i)) + 1 )

//

5

........................if m >= c_i

6

...................................if bestNumCoins_(m-c_i) + 1 < bestNumCoins_m

7

...........................................bestNumCoins_m <-- bestNumCoins_(m-c_i) + 1

//

// end of the section

//

8 return bestNumCoins_M

I don't think that you realise how much work is involved in correcting this

pseudo-code

.

RonL