Skip to content

Commit 8d24c38

Browse files
authored
[20250905] BOJ / G4 / 동전1 / 이종환
1 parent b76f0eb commit 8d24c38

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

0224LJH/202509/05 BOJ 동전1

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
```java
2+
import java.io.IOException;
3+
import java.io.*;
4+
import java.util.*;
5+
6+
7+
public class Main {
8+
static int[] dp,coins;
9+
static int coinCnt, goal;
10+
11+
public static void main(String[] args) throws IOException {
12+
init();
13+
process();
14+
print();
15+
}
16+
17+
public static void init() throws IOException {
18+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
19+
StringTokenizer st = new StringTokenizer(br.readLine());
20+
coinCnt = Integer.parseInt(st.nextToken());
21+
goal = Integer.parseInt(st.nextToken());
22+
23+
coins = new int[coinCnt];
24+
dp = new int[goal+1];
25+
dp[0] = 1;
26+
27+
for (int i = 0; i < coinCnt; i++) {
28+
coins[i] = Integer.parseInt(br.readLine());
29+
}
30+
31+
32+
}
33+
34+
public static void process() throws IOException {
35+
36+
for (int i = 0; i < coinCnt; i++) {
37+
int cost = coins[i];
38+
39+
for (int j = cost; j <= goal; j++) {
40+
dp[j] += dp[j-cost];
41+
}
42+
}
43+
44+
}
45+
46+
47+
48+
49+
50+
51+
52+
public static void print() {
53+
System.out.println(dp[goal]);
54+
}
55+
}
56+
57+
```

0 commit comments

Comments
 (0)