You are on page 1of 2

import

import
import
import
import

java.io.*;
java.util.*;
java.text.*;
java.math.*;
java.util.regex.*;

/*
#include<cstdio>
#include<cstring>
#define m 5
using namespace std;
typedef long long int ll;
ll a[5] = {1,5,10,25,50};
ll dp[1000][1000];
int main(){
ll n,i,j,x,y;
while(scanf("%lld",&n) == 1){
for(i=0;i<m;i++) dp[i][0] = 1;
for(i=0;i<m;i++)for(j=1;j<=n;j++){
x = 0; y = 0;
if(i-1 >= 0) x = dp[i-1][j];
if(j-a[i] >= 0) y = dp[i][j-a[i]];
dp[i][j] = x+y;
}
if(dp[m-1][n] != 1) printf("There are %lld ways to produce %lld cents ch
ange.\n", dp[m-1][n], n);
else printf("There is only %lld way to produce %lld cents change.\n", dp
[m-1][n], n);
}
return 0;
}

*/

public class Solution {


public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
BigInteger[] dp;
BigInteger n,x,y;
int i,j;
while(scanner.hasNextBigInteger()){
n = scanner.nextBigInteger();
for(i=0;i<m;i++) dp[i][0] = BigInteger.ONE;
for(i=0;i<m;i++)for(j=1;j<=n;j++){
x = BigInteger.ZERO; y = BigInteger.ZERO;

if(i-1 >= 0) x = dp[i-1][j];


if(j-a[i] >= 0) y = dp[i][j-a[i]];
dp[i][j] = x.add(y);
}
if(dp[m-1][n].compareTo(BigInteger.ONE) != 0) System.out.printf("The
re are %s ways to produce %s cents change.\n", dp[m-1][n].toString(10), n.toStri
ng(10));
else System.out.printf("There is only %s way to produce %s cents cha
nge.\n", dp[m-1][n].toString(10), n.toString(10));
}
}
}

You might also like