Home AtCoder. 008 AtCounter(4)
Post
Cancel

AtCoder. 008 AtCounter(4)

[Link] https://AtCoder.jp/contests/typical90/tasks/typical90_h


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
import java.util.*;
import java.io.*;

//my mistake : line 15 : if(arr[0] == str[j]) dp[0][j] = 1;
public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    int n = Integer.parseInt(reader.readLine());
    int con = (int)(1e9 + 7);
    char[] arr = reader.readLine().toCharArray();
    char[] str = "AtCoder".toCharArray();
    long[][] dp = new long[n][7];
    reader.close();

    for(int j = 0; j < 7; j++)
      if(arr[0] == 'a') dp[0][0] = 1;

    for(int i = 1; i < n; i++) { // idx of arr
      for(int j = 0; j < 7; j++) { //
        dp[i][j] = dp[i-1][j];
        if(arr[i] == str[j]) {
          if(j == 0) dp[i][j]++;
          else dp[i][j] += dp[i-1][j-1];
          dp[i][j] %= con;
        }
      }
    }
    System.out.println(dp[n - 1][6]);
  }
}
This post is licensed under CC BY 4.0 by the author.