Skip to content

Commit 5ca5312

Browse files
authored
[20250314] BOJ / P5 / 크리스마스 트리 꾸미기 / 권혁준
1 parent add3708 commit 5ca5312

File tree

1 file changed

+74
-0
lines changed

1 file changed

+74
-0
lines changed
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
```java
2+
3+
import java.util.*;
4+
import java.io.*;
5+
6+
7+
class Main {
8+
9+
// IO field
10+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
11+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
12+
static StringTokenizer st = new StringTokenizer("");
13+
14+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
15+
static int nextInt() throws Exception {
16+
if(!st.hasMoreTokens()) nextLine();
17+
return Integer.parseInt(st.nextToken());
18+
}
19+
static long nextLong() throws Exception {
20+
if(!st.hasMoreTokens()) nextLine();
21+
return Long.parseLong(st.nextToken());
22+
}
23+
static void bwEnd() throws Exception {bw.flush();bw.close();}
24+
25+
// Additional field
26+
27+
static int N, L;
28+
static long[][] dp, sum;
29+
static final long mod = 100030001L;
30+
31+
public static void main(String[] args) throws Exception {
32+
33+
ready();
34+
solve();
35+
36+
bwEnd();
37+
38+
}
39+
40+
static void ready() throws Exception{
41+
42+
N = nextInt();
43+
L = nextInt();
44+
dp = new long[N+1][N+1];
45+
sum = new long[N+1][N+1];
46+
47+
}
48+
49+
static void solve() throws Exception{
50+
51+
if(L > N) {
52+
bw.write("0");
53+
return;
54+
}
55+
dp[0][0] = 1;
56+
for(int i=0;i<=L;i++) sum[0][i] = 1;
57+
for(int h=1;h<=L;h++) for(int n=1;n<=N;n++) {
58+
59+
for(int k=0;k<n;k++) {
60+
dp[n][h] += sum[k][h-1] * dp[n-1-k][h-1];
61+
dp[n][h] += dp[k][h-1] * sum[n-1-k][h-1];
62+
dp[n][h] -= dp[k][h-1] * dp[n-1-k][h-1];
63+
dp[n][h] = (dp[n][h] + mod) % mod;
64+
}
65+
66+
sum[n][h] = (sum[n][h-1] + dp[n][h]) % mod;
67+
}
68+
bw.write(dp[N][L] + "\n");
69+
70+
}
71+
72+
}
73+
74+
```

0 commit comments

Comments
 (0)