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; I know how I want to do this but, I do not know how to implement it. Example: 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: This should be correct if I think you are right, basically it is a clear move to implement the recycling ... Obviously this takes the
zero dynamic (int n, int * a, int value) {arr [0] = 0; For (int i = 1; i
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.
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 ]];
f [i , J] = f [i-1, j] f [i-1, ja [i]];
o (n value) time.
Comments
Post a Comment