Let T(v) be the minimum number of coins needed.
We have 鈥榥鈥 number of coins of denomination, where we have check for the possibility to make a change for value v by taking at most k coins from given denominations.
The supply of coins of denominations and to make change for a value v using at most k coins, that is, we wish to find a set of coins whose total value. This might not be possible: for instance, if the denominations are 5 and 10 and k=6 then we can make change for 55 but not for 65.
To achieve this, we will create dynamic algorithm where first we need to find the least number of coins needed to get value v. After this, comparing it with 鈥榢鈥 coins to check if we can make value using k coins only.
So, the recurrence relation will be:
Here we take an array Change [] with v elements in it. This means the length of array Change [] will be v. We will take the value of each element as 鈥榠nfinity鈥. Here value at index 鈥榡鈥 will tell about the number of coins need to make value. So, when we trace index 鈥榲鈥, the algorithm will check if the value at index 鈥榲鈥 is less than 鈥榢鈥. to compute only distinct function call because as soon as compute and store in one data structure so that after this reuse afterward if it is needed.
So, algorithm will return true if the condition is satisfied else, return false.