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]);
}
}
}
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]);
}
}
}
0 comments :
Post a Comment