Coin changing problem:
Greedy approach:
N=20
Coin ={1,5,10}
20-10=10 1
10-10=0 2
(10+10 ) rs have two 2 coin
Or
20-10=10
5___> 10-5=5
5---- 5-5=0
Total number of coins=3
Problem 2:
N=41
Coin= {4, 10 ,25}
Solved by greedy approach:
25--- 41-25= 16
10-> 16-10= 6
4-> 6-4=2 3= total number of coins
According to greedy approach, solution does not exist.
(25,4,4,4,4) according to this , solution is exist.
Greedy approach is fail
Solution is exist by DP.
Coin changing problem by DP:
N=4
Changing coin ={1,2,3}
i/j 0 1 2 3 4
1 1 1 1 1 1
2 1 1 2 2 3
3 1 1 2 3 4
0 having no chance : 1
Number of max ways to have change : 1111
22
2 11
31