Problem Statement:
Print all unique combinations of Coin change for a given amount.
Combinations for Amount 5 , from the given denominations
Download Source Code
Solution:
For finding the optimal solution of the given problem, we will use Backtracking.
Below is the sub-routine implementation.
Please post your comments and suggestions.
Happy Coding !! :)
Print all unique combinations of Coin change for a given amount.
Combinations for Amount 5 , from the given denominations
Fig: Change for Amount 5 |
Solution:
For finding the optimal solution of the given problem, we will use Backtracking.
Below is the sub-routine implementation.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | /** * Prints all comninations of the coin change */ public static void coinCombinations(int amount,int index,LinkedList<Integer> list) { if(amount==0) { count++; System.out.println(list.toString()); return ; } if(amount < 0) return ; for(int i=index ; i < coins.size();i++) { int coin = coins.get(i); if(amount >= coin) { list.add(coin); coinCombinations(amount - coin ,i,list ); list.removeLast(); } } } |
Please post your comments and suggestions.
Happy Coding !! :)
Greetings! Very helpful advice within this post!
ReplyDeleteIt is the little changes which will make the greatest changes.
Thanks a lot for sharing!
Here is my web-site ... simply click the up coming web site
lebron shoes
ReplyDeletekobe 11
huarache shoes
curry shoes
hermes bag
cheap jordans
vapormax
moncler outlet
vans shoes
kate spade outlet