6879.Required Substring

Time Limit: 1s Memory Limit: 512MB

Your task is to calculate the number of strings of length $n$ having a given pattern of length $m$ as their substring. All strings consist of characters A–Z.

Input Format(From the terminal/stdin)

The first input line has an integer $n$ : the length of the final string.

The second line has a pattern of length $m$ .

  • $1 \le n \le 1000$
  • $1 \le m \le 100$

Output Format(To the terminal/stdout)

Print the number of strings modulo $10^9+7$ .

Sample Input

Copy
6
ABCDB
 \n
     \n

Sample Output

Copy
52
  \n

The final string will be of the form ABCDB $x$ or $x$ ABCDB where $x$ is any character between A–Z.

Source: CSES, String Algorithms, 1112

Submit

请先 登录

© 2025 FAQs