#P16017. [ICPC 2021 NAC] Ketek Counting
[ICPC 2021 NAC] Ketek Counting
题目描述
Define a Ketek to be a sentence that reads the same forwards and backwards, by word. For example, ‘fall leaves after leaves fall’ is a Ketek since the words in reverse order are the same as the original order.
Given a string consisting of lower-case letters and the character ‘?’, count the number of distinct Keteks you can make by replacing every ‘?’ with lower-case letters (one letter per ‘?’), and optionally adding spaces between any letters. Note that a Ketek cannot contain any ?’s; they all must be replaced exclusively by lower-case letters.
For example, if we start with the string ‘ababa’, we can form 3 different Keteks: ‘ababa’, ‘a bab a’ and ‘a b a b a’.
If we start with the string ‘?x?z’ instead, we can form 703 different Keteks:
- There are ways to replace the ?’s and form a one-word Ketek.
- Add spaces to form ‘? x? z’. There are 26 ways to form a Ketek (the first ‘?’ must be z; the other can be any lower-case letter).
- Add a space to form ‘?x ?z’. There is no way to form a Ketek.
- Add spaces to form ‘? x ? z’. There is one way to form a Ketek (the first ‘?’ must be z; the second must be x).
The total is .
Two Keteks are different if they have a different number of words, or there is some word index where the words are not the same.
输入格式
The single line of input contains a string (), which consists of lower-case letters (‘a’–‘z’) and the character ‘?’.
输出格式
Output the number of distinct Keteks that can be formed by replacing the ?’s with lower-case letters and adding spaces. Since this number may be large, output it modulo .
ababa
3
?x?z
703