Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class ClassicATM {
- final public static int INF = 1000000000;
- public static void main(String[] args) {
- int s = 25;
- int a [] = {10, 8, 6, 1};
- int d[] = new int[s+1];
- d[0]=0;
- for (int m=1; m<=s; m++) {
- d[m]=INF;
- for (int i=0; i<a.length; i++) {
- if (m>=a[i] && d[m-a[i]]+1<d[m]) {
- d[m] = d[m-a[i]]+1;
- }
- }
- }
- if (d[s]==INF) {
- System.out.println("ERROR");
- } else {
- while(s>0) {
- for (int i=0; i<a.length; i++) {
- if (d[s-a[i]]==d[s]-1) {
- System.out.println(a[i]+" ");
- s-=a[i];
- break;
- }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement