-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAtCounter_008.java
More file actions
38 lines (32 loc) · 855 Bytes
/
AtCounter_008.java
File metadata and controls
38 lines (32 loc) · 855 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package java;
import java.util.*;
/**
* 008 - AtCounter(★4)
* 状態DP法
*/
public class AtCounter_008 {
private static final int MOD = (int) Math.pow(10, 9) + 7;
private static final String[] T = "atcoder".split("");
private static int N;
private static String[] S;
private static int[][] dp;
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
N = sc.nextInt();
S = sc.next().split("");
dp = new int[N + 1][T.length + 1];
for (int i = 0; i < N + 1; i++) {
dp[i][0] = 1;
}
for (int i = 0; i < N; i++) {
for (int j = 0; j < T.length; j++) {
dp[i + 1][j + 1] = dp[i][j + 1];
if (S[i].equals(T[j])) {
dp[i + 1][j + 1] += dp[i][j];
dp[i + 1][j + 1] %= MOD;
}
}
}
System.out.println(dp[N][T.length]);
}
}