Skip to content

Commit 89dba1a

Browse files
authored
Merge pull request #730 from AlgorithmWithGod/0224LJH
[20250824] BOJ / G5 / 동전 / 이종환
2 parents 5c2437e + a824447 commit 89dba1a

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

0224LJH/202508/24 BOJ 동전.md

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

0 commit comments

Comments
 (0)