Skip to content

Commit a666034

Browse files
authored
Merge pull request #1506 from AlgorithmWithGod/lkhyun
[20251125] BOJ / G3 / 색상환 / 이강현
2 parents cd44ef3 + 9f06896 commit a666034

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
public class Main{
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static StringBuilder sb = new StringBuilder();
10+
static int N,K;
11+
static int[][] dp;
12+
static int MOD = 1000000003;
13+
14+
public static void main(String[] args) throws Exception {
15+
N = Integer.parseInt(br.readLine());
16+
K = Integer.parseInt(br.readLine());
17+
dp = new int[N+1][K+1]; //N개의 색중 K개를 선택하는 경우의 수
18+
19+
for(int i=0;i<=N;i++){
20+
dp[i][1] = i; //색 i를 칠하는 경우의 수 여기서 1개를 색칠하는 경우는 i개임.
21+
dp[i][0] = 1;
22+
}
23+
for(int i = 2;i<=N;i++){
24+
for(int j = 2;j<=K;j++){
25+
dp[i][j] = (dp[i-1][j] + dp[i-2][j-1]) % MOD;
26+
}
27+
}
28+
29+
int ans = (dp[N-1][K] + dp[N-3][K-1]) % MOD;
30+
bw.write(ans+"");
31+
bw.close();
32+
}
33+
}
34+
```

0 commit comments

Comments
 (0)