#P7114. [NOIP2020] 字符串匹配
[NOIP2020] 字符串匹配
Problem Description
After learning about string matching, Little C is now working on a problem.
For a string , the task asks him to find the number of all split plans of that have one of the following forms:
, , , where , , and are all non-empty strings, and the number of characters that appear an odd number of times in is not greater than the number of characters that appear an odd number of times in .
More specifically, we define as the concatenation of two strings and . For example, if and , then .
We also define recursively and ( and is a positive integer). For example, if , then .
Then Little C's exercise is to find the number of plans such that , where . Here, denotes the number of characters that appear an odd number of times in the string . Two plans are different if and only if at least one of the split strings , , and is different.
Little C cannot solve this problem, so he asks you for help. Please help him.
Input Format
This problem contains multiple test cases. The first line of the input file contains a positive integer , indicating the number of test cases.
Each test case contains one line with a string , as described above. consists only of lowercase English letters.
Output Format
For each test case, output one integer per line, representing the answer.
3
nnrnnr
zzzaab
mmlmmlo
8
9
16
5
kkkkkkkkkkkkkkkkkkkk
lllllllllllllrrlllrr
cccccccccccccxcxxxcc
ccccccccccccccaababa
ggggggggggggggbaabab
156
138
138
147
194
见附件中的 string/string3.in
见附件中的 string/string3.ans
见附件中的 string/string4.in
见附件中的 string/string4.ans
Hint
【Sample #1 Explanation】
For the first test case, all valid plans are:
- , , .
- , , .
- , , .
- , , .
- , , .
- , , .
- , , .
- , , .
【Constraints】
| Test Point ID | Special Property | |
|---|---|---|
| None | ||
| contains only one kind of character | ||
| contains only two kinds of characters | ||
| None | ||
For all test points, it is guaranteed that and .
Translated by ChatGPT 5