fork(12) download
  1. /**
  2.  * Created by sumisha on 3/1/2016.
  3.  */
  4. import java.util.ArrayList;
  5. import java.util.Date;
  6. import java.util.List;
  7. import java.util.Random;
  8.  
  9. public class Main {
  10. static int[] coinSet = {1,5,10,25};
  11. static List<List<Integer>> possibleWays = new ArrayList<>();
  12. static List<Integer> currentWay = new ArrayList<>();
  13. public static void main(String[] args) {
  14. List<Integer> countOfCoins = new ArrayList<>();
  15. makeChange(7, 0, countOfCoins);
  16. //System.out.print(possibleWays);
  17. }
  18.  
  19. private static int makeChange(int amount, int startCoinIdx, List<Integer> coinsSoFar) {
  20. if(startCoinIdx == coinSet.length){
  21. if(amount == 0){
  22. possibleWays.add(coinsSoFar);
  23. System.out.println(coinsSoFar);
  24. }
  25. //System.out.println(coinsSoFar);
  26. return 0;
  27. }
  28. for(int count = 0;(count*coinSet[startCoinIdx]) <= amount;count++){
  29. List<Integer> temp = new ArrayList<>();
  30. for(int i = 0;i < coinsSoFar.size();i++) temp.add(coinsSoFar.get(i));
  31. for(int i = 0;i < count;i++) temp.add(coinSet[startCoinIdx]);
  32. makeChange(amount - (count * coinSet[startCoinIdx]),startCoinIdx+1, temp);
  33. temp.clear();
  34. }
  35. return 0;
  36. }
  37. }
  38.  
Success #stdin #stdout 0.11s 320576KB
stdin
Standard input is empty
stdout
[1, 1, 5]
[1, 1, 1, 1, 1, 1, 1]