Coin change problem C++ -


I have a problem writing a dynamic algorithm to solve the problem of coin change that I have found:

A [n] - an array with coin values;

  zero dynamic (int n, int * a, int value) {arr [0] = 0; For (int i = 1; i   

I know how I want to do this but, I do not know how to implement it.

Example:
Suppose I have coins to solve 1 4 10 15 40 and value 37. I am filled in AR like this: If the value of the coin = i i [i] = 1; For the next element, as long as I'm less than the next coin, I keep the previous value + 1, the IR [1-1] + 1. 1. So it should prefer 1 [1] 1 = 2, 2 = 2, 3 I = 3, 4 = 1, 5 = 2 and so on, but I'm missing something and I do not know that I I want to fix it.

Can anyone help me with the way I want it? I am trying to understand it, but I have not got anything. I have also used the entire algorithm, but it is very slow, so I have to type it again.

You may want to:

  memset (arr, 0 , Sizeof (arr)); Advent [0] 1 =; For (int i = 0; i & lt; n; ++ i) for (int j = a [i]; j & lt; value; ++ j) arr [j] + = arr [ja [i ]];   

This should be correct if I think you are right, basically it is a clear move to implement the recycling ...

  f [i , J] = f [i-1, j] f [i-1, ja [i]];   

Obviously this takes the o (n value) time.

Comments