/**
* Created by sumisha on 3/1/2016.
*/
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;
public class Main {
static int[] coinSet = {1,5,10,25};
static List<List<Integer>> possibleWays = new ArrayList<>();
static List<Integer> currentWay = new ArrayList<>();
public static void main
(String[] args
) { List<Integer> countOfCoins = new ArrayList<>();
makeChange(7, 0, countOfCoins);
//System.out.print(possibleWays);
}
private static int makeChange(int amount, int startCoinIdx, List<Integer> coinsSoFar) {
if(startCoinIdx == coinSet.length){
if(amount == 0){
possibleWays.add(coinsSoFar);
System.
out.
println(coinsSoFar
); }
//System.out.println(coinsSoFar);
return 0;
}
for(int count = 0;(count*coinSet[startCoinIdx]) <= amount;count++){
List<Integer> temp = new ArrayList<>();
for(int i = 0;i < coinsSoFar.size();i++) temp.add(coinsSoFar.get(i));
for(int i = 0;i < count;i++) temp.add(coinSet[startCoinIdx]);
makeChange(amount - (count * coinSet[startCoinIdx]),startCoinIdx+1, temp);
temp.clear();
}
return 0;
}
}
LyoqCiAqIENyZWF0ZWQgYnkgc3VtaXNoYSBvbiAzLzEvMjAxNi4KICovCmltcG9ydCBqYXZhLnV0aWwuQXJyYXlMaXN0OwppbXBvcnQgamF2YS51dGlsLkRhdGU7CmltcG9ydCBqYXZhLnV0aWwuTGlzdDsKaW1wb3J0IGphdmEudXRpbC5SYW5kb207CgpwdWJsaWMgY2xhc3MgTWFpbiB7CiAgICBzdGF0aWMgaW50W10gY29pblNldCA9IHsxLDUsMTAsMjV9OwogICAgc3RhdGljIExpc3Q8TGlzdDxJbnRlZ2VyPj4gcG9zc2libGVXYXlzID0gbmV3IEFycmF5TGlzdDw+KCk7CiAgICBzdGF0aWMgTGlzdDxJbnRlZ2VyPiBjdXJyZW50V2F5ID0gbmV3IEFycmF5TGlzdDw+KCk7CiAgICBwdWJsaWMgc3RhdGljIHZvaWQgbWFpbihTdHJpbmdbXSBhcmdzKSB7CiAgICAgICAgTGlzdDxJbnRlZ2VyPiBjb3VudE9mQ29pbnMgPSBuZXcgQXJyYXlMaXN0PD4oKTsKICAgICAgICBtYWtlQ2hhbmdlKDcsIDAsIGNvdW50T2ZDb2lucyk7CiAgICAgICAgLy9TeXN0ZW0ub3V0LnByaW50KHBvc3NpYmxlV2F5cyk7CiAgICB9CgogICAgcHJpdmF0ZSBzdGF0aWMgaW50IG1ha2VDaGFuZ2UoaW50IGFtb3VudCwgaW50IHN0YXJ0Q29pbklkeCwgTGlzdDxJbnRlZ2VyPiBjb2luc1NvRmFyKSB7CiAgICAgICAgaWYoc3RhcnRDb2luSWR4ID09IGNvaW5TZXQubGVuZ3RoKXsKICAgICAgICAgICAgaWYoYW1vdW50ID09IDApewogICAgICAgICAgICAgICAgcG9zc2libGVXYXlzLmFkZChjb2luc1NvRmFyKTsKICAgICAgICAgICAgICAgIFN5c3RlbS5vdXQucHJpbnRsbihjb2luc1NvRmFyKTsKICAgICAgICAgICAgfQogICAgICAgICAgICAvL1N5c3RlbS5vdXQucHJpbnRsbihjb2luc1NvRmFyKTsKICAgICAgICAgICAgcmV0dXJuIDA7CiAgICAgICAgfQogICAgICAgIGZvcihpbnQgY291bnQgPSAwOyhjb3VudCpjb2luU2V0W3N0YXJ0Q29pbklkeF0pIDw9IGFtb3VudDtjb3VudCsrKXsKICAgICAgICAgICAgTGlzdDxJbnRlZ2VyPiB0ZW1wID0gbmV3IEFycmF5TGlzdDw+KCk7CiAgICAgICAgICAgIGZvcihpbnQgaSA9IDA7aSA8IGNvaW5zU29GYXIuc2l6ZSgpO2krKykgdGVtcC5hZGQoY29pbnNTb0Zhci5nZXQoaSkpOwogICAgICAgICAgICBmb3IoaW50IGkgPSAwO2kgPCBjb3VudDtpKyspIHRlbXAuYWRkKGNvaW5TZXRbc3RhcnRDb2luSWR4XSk7CiAgICAgICAgICAgIG1ha2VDaGFuZ2UoYW1vdW50IC0gKGNvdW50ICogY29pblNldFtzdGFydENvaW5JZHhdKSxzdGFydENvaW5JZHgrMSwgdGVtcCk7CiAgICAgICAgICAgIHRlbXAuY2xlYXIoKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIDA7CiAgICB9Cn0K
[1, 1, 5]
[1, 1, 1, 1, 1, 1, 1]