#abc305g. G - Banned Substrings
G - Banned Substrings
Score : points
问题描述
给定一个包含长度最多为6个由字符a
和b
组成的非空字符串集合 。要求找出满足以下条件的长度为 的仅包含字符a
和b
的字符串 的数量:
- 对于集合 中的所有 ,字符串 都不含有连续子串 。
由于答案可能非常大,请计算结果对 取模后的值。
以上为通义千问 qwen-max 翻译,仅供参考。
Problem Statement
You are given a set of non-empty strings of length at most consisting of a
and b
. Find the number of strings of length consisting of a
and b
that satisfy the following condition:
- does not contain as a consecutive substring for any .
Since the answer can be enormous, find it modulo .
Constraints
- and are integers.
- is a non-empty string of length at most consisting of
a
andb
.
Input
The input is given from Standard Input in the following format:
Output
Print the answer modulo in a single line.
Sample Input 1
4 3
aab
bbab
abab
Sample Output 1
10
There are strings of length consisting of a
and b
that do not contain aab
, bbab
, or abab
as consecutive substrings: aaaa
, abaa
, abba
, abbb
, baaa
, baba
, babb
, bbaa
, bbba
, and bbbb
. Thus, you should print .
Sample Input 2
20 1
aa
Sample Output 2
17711
Sample Input 3
1000000007 28
bbabba
bbbbaa
aabbab
bbbaba
baaabb
babaab
bbaaba
aabaaa
aaaaaa
aabbaa
bbaaaa
bbaabb
bbabab
aababa
baaaba
ababab
abbaba
aabaab
ababaa
abbbba
baabaa
aabbbb
abbbab
baaaab
baabbb
ababbb
baabba
abaaaa
Sample Output 3
566756841
Print the answer modulo .
update @ 2024/3/10 08:37:09