8972: String Problem

内存限制:64 MB 时间限制:1 S
题面:传统 评测方式:文本比较 上传者:
提交:14 通过:13

题目描述

Little L raised a question:

Given a string S of length n containing only lowercase letters.

You need to select several non-empty substrings of S so that they are disjoint pairwise, and each substring is a palindrome.

Assuming you have selected K substrings(�1,�2...��s1,s2...sk) that satisfy the above conditions, your score is the sum of the lengths of all substrings minus K. It is ∑�=1����(��)−�i=1Klen(si)K

But Little L is a dedicated person, and to increase difficulty, Little L requires that each palindrome string contain at most one kind of letter

Little L wants you to find the maximum score.

输入格式

A positive integer T in the first line represents the number of test groups, for each group of test data:

The only line contains a string of length n which containing only lowercase letters.

�≤20,∑�≤106T20,n106

输出格式

For each test data, print a number representing the maximum score.

输入样例 复制

2
etxabaxtezwkdwokdbbb
aaaaa

输出样例 复制

2
4

分类标签