674 - Coin Change (Uva Solution)

674 - Coin Change

import java.util.Scanner;

class Main {
public static long [] ways=new long [10000];

public static void main(String[] args) {


Scanner sc =new Scanner(System.in);
int n;
int [] coin=new int[5];
coin[0]=1;
coin[1]=5;
coin[2]=10;
coin[3]=25;
coin[4]=50;
int i,j;
ways[0]=1;
for(i=0;i<5;i++){
for(j=coin[i];j<10000;j++){
ways[j]+=ways[j-coin[i]];

}

}
while(sc.hasNext())
{

n=sc.nextInt();




System.out.println(ways[n]);

}

}


}

SHARE

Amit Ghosh

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment