File size: 578 Bytes
c574d3a |
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 28 29 30 31 32 33 34 |
class Recurcoin{
// n is the amount and array is the notes
// we need to find the minimum notes that sums the n
static int mincoin(int n, int a[]){
if(n==0) return 0;
int ans = Integer.MAX_VALUE;
for(int i=0; i<a.length; i++){
if(n-a[i] >= 0){
int sub = mincoin(n-a[i],a);
if(sub!=Integer.MAX_VALUE && sub+1 < ans){
ans = sub+1;
}
}
}
return ans;
}
public static void main(String[] args){
int n = 18;
int a[] = {5,7,1};
System.out.println(mincoin(n,a));
}
}
|