1

Given a sum amount 1.15 Rs. (1 Rs. = 100 Paise), so total 115 paise and given a list of 8 coins with denominations as {1, 2, 5, 10, 20, 25, 50, 100} paise. Find 6 coins which sum to 1.15 Rs. The constraint is that I should not be able to give change from my solution for the amounts given in a restricted set. The restricted set here is {5, 10, 20, 25}.

Appreciate any solutions or pointers.

Rajendra Uppal
  • 19,218
  • 15
  • 59
  • 57
  • What do you mean by restricted set?. Does this mean you must compulsorily use coins from this restricted set??? – NinjaCoder Mar 11 '12 at 15:34
  • Did you want solutions or pointers for the general case or this specific case ? – Appleman1234 Mar 11 '12 at 19:40
  • The way your question is worded, you imply that you cannot use any coins in the restricted set. How then can you get 115 in 6 coins using the remaining set `{1, 2, 50, 100}`? {100,2,2,2,2,2.. 6 coins already}, there is no solution. I think what you mean to say is that you can't use any coins outside of this subset, in which case knowing the overall 8 coins is not needed as we only have one set to consider this also has a solvable answer `{25, 25, 25, 25, 10, 5}` in 6 coins. – Seph Mar 13 '12 at 05:27

1 Answers1

1

Is this what you are looking for?

import java.util.Arrays;
public class Coining {

public static void getChange(int amount, int[] denomination){
    Arrays.sort(denomination);//sort the array
    for(int coin=denomination.length-1; coin>=0;coin--){
        int coef = amount/denomination[coin];
        amount%=denomination[coin];
        if(coef > 0)
            System.out.format("%d {%d Paise}%n",coef, denomination[coin]);
        if(amount == 0)
            return;
    }
}//

public static void main(String... args){
    //int coins[]={1,2,5,10,20,25,50,100}; THIS IS IRRELEVANT.
    int restricted[]={5,10,20,25};
    int amount = 115;
    getChange(amount,restricted);
}//
}
kasavbere
  • 5,873
  • 14
  • 49
  • 72