Skip to content

Commit 18e4a64

Browse files
committed
[20251127] BOJ / G3 / 색상환 / 김민진
1 parent cfe0c2b commit 18e4a64

File tree

1 file changed

+44
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)