File tree Expand file tree Collapse file tree 1 file changed +44
-0
lines changed
Expand file tree Collapse file tree 1 file changed +44
-0
lines changed Original file line number Diff line number Diff line change 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+ ```
You can’t perform that action at this time.
0 commit comments