**V**,

_{1}**V**, ... ,

_{2}**V**), and the total sum

_{N}**S**. Find the minimum number of coins the sum of which is

**S**(we can use as many coins of one type as we want), or report that it's not possible to select coins in such a way that they sum up to

**S**."

**j, V**, look at the minimum number of coins found for the

_{j}≤i**i-V**sum (we have already found it previously). Let this number be

_{j}**m**. If

**m+1**is less than the minimum number of coins already found for current sum

**i**, then we write the new result for it.

**S**is set to be 11.

**V**= 0 we have a solution with 0 coins. Because we add one coin to this solution, we'll have a solution with 1 coin for sum 1. It's the only solution yet found for this sum. We write (save) it. Then we proceed to the next state -

_{1}**sum 2**. We again see that the only coin which is less or equal to this sum is the first coin, having a value of 1. The optimal solution found for sum (2-1) = 1 is coin 1. This coin 1 plus the first coin will sum up to 2, and thus make a sum of 2 with the help of only 2 coins.This is the best and only solution for sum 2. Now we proceed to sum 3. We now have 2 coins which are to be analyzed - first and second one, having values of 1 and 3. Let's see the first one. There exists a solution for sum 2 (3 - 1) and therefore we can construct from it a solution for sum 3 by adding the first coin to it. Because the best solution for sum 2 that we found has 2 coins, the new solution for sum 3 will have 3 coins. Now let's take the second coin with value equal to 3. The sum for which this coin needs to be added to make 3 , is 0. We know that sum 0 is made up of 0 coins. Thus we can make a sum of 3 with only one coin - 3. We see that it's better than the previous found solution for sum 3 , which was composed of 3 coins. We update it and mark it as having only 1 coin. The same we do for sum 4, and get a solution of 2 coins - 1+3. And so on.

Sum Min. nr. of coins Coin value added to a smaller sum to

obtain this sum (it is displayed in brackets)0 0 - 1 1 1 (0) 2 2 1 (1) 3 1 3 (0) 4 2 1 (3) 5 1 5 (0) 6 2 3 (3) 7 3 1 (6) 8 2 3 (5) 9 3 1 (8) 10 2 5 (5) 11 3 1 (10)

**Subscribe**- To get an automatic feed of all future posts subscribe here, or to receive them via email go here and enter your email address in the box. You can also like us on facebook and follow me on Twitter @akashag1001.