Skip to content

Commit f913844

Browse files
authored
Merge pull request #818 from AlgorithmWithGod/khj20006
[20250904] BOJ / P5 / 징검다리 뒤로 건너기 / 권혁준
2 parents 2e54555 + d544c3a commit f913844

File tree

1 file changed

+90
-0
lines changed

1 file changed

+90
-0
lines changed
Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
```java
2+
import java.util.*;
3+
import java.io.*;
4+
5+
class IOController {
6+
BufferedReader br;
7+
BufferedWriter bw;
8+
StringTokenizer st;
9+
10+
public IOController() {
11+
br = new BufferedReader(new InputStreamReader(System.in));
12+
bw = new BufferedWriter(new OutputStreamWriter(System.out));
13+
st = new StringTokenizer("");
14+
}
15+
16+
String nextLine() throws Exception {
17+
String line = br.readLine();
18+
st = new StringTokenizer(line);
19+
return line;
20+
}
21+
22+
String nextToken() throws Exception {
23+
while (!st.hasMoreTokens()) nextLine();
24+
return st.nextToken();
25+
}
26+
27+
int nextInt() throws Exception {
28+
return Integer.parseInt(nextToken());
29+
}
30+
31+
long nextLong() throws Exception {
32+
return Long.parseLong(nextToken());
33+
}
34+
35+
double nextDouble() throws Exception {
36+
return Double.parseDouble(nextToken());
37+
}
38+
39+
void close() throws Exception {
40+
bw.flush();
41+
bw.close();
42+
}
43+
44+
void write(String content) throws Exception {
45+
bw.write(content);
46+
}
47+
48+
}
49+
50+
public class Main {
51+
52+
static IOController io;
53+
54+
//
55+
56+
static final long MOD = (long)1e9 + 7;
57+
58+
static int N, K;
59+
static long[][] dp;
60+
61+
public static void main(String[] args) throws Exception {
62+
63+
io = new IOController();
64+
65+
N = io.nextInt();
66+
K = io.nextInt();
67+
if(N <= 2) {
68+
io.write("1\n");
69+
return;
70+
}
71+
72+
dp = new long[N+1][K+1];
73+
for(int i=3;i<=N;i++) for(int x=1;x<=K && i-x>0;x++) {
74+
if(i-x <= 2) dp[i][x] = (dp[i][x] + 1) % MOD;
75+
else for(int y=1;y<=K && i-x-y>0;y++) {
76+
if(i-x-y <= 2) dp[i][x] = (dp[i][x] + (i-x+1-Math.max(i-x-y+1,i-K))) % MOD;
77+
else dp[i][x] = (dp[i][x] + dp[i-x][y] * (i-x+1-Math.max(i-x-y+1,i-K))) % MOD;
78+
}
79+
}
80+
81+
long ans = 0;
82+
for(int x=1;x<=K && N-x>0;x++) ans = (ans + dp[N][x]) % MOD;
83+
io.write(ans + "\n");
84+
85+
io.close();
86+
87+
}
88+
89+
}
90+
```

0 commit comments

Comments
 (0)