-
Notifications
You must be signed in to change notification settings - Fork 0
/
money.java
52 lines (47 loc) · 1.23 KB
/
money.java
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
ID: 001207j1
LANG: JAVA
TASK: money
*/
import java.io.*;
import java.util.*;
public class money {
public static void main(String[] args) throws IOException {
money m = new money();
m.run();
}
public static void run() throws IOException {
long start_Time = System.currentTimeMillis();
BufferedReader f = new BufferedReader(new FileReader("money.in"));
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("money.out")));
String[] s = f.readLine().split(" ");
int V = Integer.parseInt(s[0]);
int N = Integer.parseInt(s[1]);
Set<Integer> a = new HashSet<Integer>();
String str;
while ((str = f.readLine()) != null) {
s = str.split(" ");
for (int i = 0; i < s.length; i++)
a.add(Integer.parseInt(s[i]));
}
V = a.size();
Integer nums[] = a.toArray(new Integer[V]);
long[][] sum = new long[V + 1][N + 1];
for (int i = 0; i <= V; i++)
sum[i][0] = 1;
for (int i = 1; i <= V; i++)
for (int j = 1; j <= N; j++) {
if (i == 1 && j % nums[i - 1] != 0)
continue;
int x = j;
while (x >= 0) {
sum[i][j] += sum[i - 1][x];
x -= nums[i - 1];
}
}
out.println(sum[V][N]);
f.close();
out.close();
System.out.println(System.currentTimeMillis() - start_Time);
}
}