Skip to content

Commit e74febd

Browse files
authored
Merge pull request #1021 from AlgorithmWithGod/zinnnn37
[20251002] BOJ / G4 / 동전 1 / 김민진
2 parents 06c47a9 + cb11c9a commit e74febd

File tree

2 files changed

+47
-2
lines changed

2 files changed

+47
-2
lines changed

zinnnn37/202510/1 BOJ G4 구슬게임.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
```java
2-
package etc;
3-
42
import java.io.*;
53
import java.util.StringTokenizer;
64

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```java
2+
import java.io.*;
3+
import java.util.StringTokenizer;
4+
5+
public class BJ_2293_동전_1 {
6+
7+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
8+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
9+
private static StringTokenizer st;
10+
11+
private static int N, K;
12+
private static int[] dp, coins;
13+
14+
public static void main(String[] args) throws IOException {
15+
init();
16+
sol();
17+
}
18+
19+
private static void init() throws IOException {
20+
st = new StringTokenizer(br.readLine());
21+
N = Integer.parseInt(st.nextToken());
22+
K = Integer.parseInt(st.nextToken());
23+
24+
dp = new int[K + 1];
25+
coins = new int[N];
26+
for (int i = 0; i < N; i++) {
27+
coins[i] = Integer.parseInt(br.readLine());
28+
}
29+
dp[0] = 1;
30+
}
31+
32+
private static void sol() throws IOException {
33+
for (int coin : coins) {
34+
for (int i = 1; i <= K; i++) {
35+
if (i - coin < 0) continue;
36+
37+
dp[i] += dp[i - coin];
38+
}
39+
}
40+
bw.write(dp[K] + "");
41+
bw.flush();
42+
bw.close();
43+
br.close();
44+
}
45+
46+
}
47+
```

0 commit comments

Comments
 (0)