#P14021. [ICPC 2024 Nanjing R] 博德之跃 2
[ICPC 2024 Nanjing R] 博德之跃 2
Description
You are given a string consisting of lower-cased English letters. You need to perform some operations on until it becomes empty. Each time you can perform one of the following three operations:
- Delete the first character of .
- Delete the last character of .
- Choose a good substring of and replace with .
A non-empty string is called a good substring of string if and only if , is a prefix of , and the reverse of is a suffix of . The reverse of a string of length is another string of length .
What's the maximum number of type operations can you perform?
Input Format
There are multiple test cases. The first line of the input contains an integer indicating the number of test cases. For each test case:
The first and only line contains a string () consisting of lower-cased English letters.
It is guaranteed that the sum of over all test cases does not exceed .
Output Format
For each test case, output one line containing one integer indicating the maximum number of type operations you can perform.
3
aaaa
abbaabba
xy
3
4
0
Hint
For the first sample test case: $\texttt{aaaa} \xrightarrow{\text{op. 3}} \texttt{aaa} \xrightarrow{\text{op. 3}} \texttt{aa} \xrightarrow{\text{op. 3}} \texttt{a} \xrightarrow{\text{op. 2}} \varnothing$.
For the second sample test case: $\texttt{abbaabba} \xrightarrow{\text{op. 3}} \texttt{abbaabb} \xrightarrow{\text{op. 1}} \texttt{bbaabb} \xrightarrow{\text{op. 3}} \texttt{bbaab} \xrightarrow{\text{op. 1}} \texttt{baab} \xrightarrow{\text{op. 3}} \texttt{baa} \xrightarrow{\text{op. 1}} \texttt{aa} \xrightarrow{\text{op. 3}} \texttt{a} \xrightarrow{\text{op. 1}} \varnothing$.
京公网安备 11011102002149号