Skip to content

Commit 86384c0

Browse files
authored
[20251223] BOJ / G3 / 준오는 심술쟁이!! / 한종욱
1 parent 6492c6d commit 86384c0

File tree

1 file changed

+51
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)