-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathCoinSums.java
More file actions
36 lines (27 loc) · 990 Bytes
/
CoinSums.java
File metadata and controls
36 lines (27 loc) · 990 Bytes
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
35
36
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int num = scanner.nextInt();
int target = 100000;
BigInteger[] ways = new BigInteger[target+1];
for(int i=0;i<ways.length;i++)
ways[i] = BigInteger.valueOf(0);
ways[0] = BigInteger.valueOf(1);
int[] coinSizes = { 1, 2, 5, 10, 20, 50, 100, 200 };
for (int i = 0; i < coinSizes.length; i++) {
for (int j = coinSizes[i]; j <= target; j++) {
ways[j] = ways[j].add(ways[j - coinSizes[i]]);
}
}
for(int k=0;k<numberOfTestCases;k++) {
int n = scanner.nextInt();
System.out.println(ways[n].mod(BigInteger.valueOf(1000000007)));
}
scanner.close();
}
}