Problem Description
Baby volcano is helping his CCPC coach preparing a new CCPC training contest. He wants to generate high quality data on border tree(There is no need to know what border tree is), but he encounters some troubles. Could you please help him?
In this paragraph we formally define the data quality problem. For some string s=s1s2s3⋯sn, we use s[l:r] to denote the substring starts from l and ends at r, if l>r, s[l:r] is empty. We further define:Lborderi=max{0≤j<i | s[1:j]=s[i−j+1:i]}
to denote the longest border at some position i, then we define D(i) to denote the length of border chain at position i:D(i)={0D(LBorderi)+1i=0i>0
The quality W of this string is define as the maximum of D:W=maxi=0nD(i)
To distinguish border tree with naive brute force algorithms, baby volcano need to generate strings such that its quality W is as large as possible.
Now given a string s, you could permute s arbitrarily. What is the maximum quality W you could reach after permuting s?Input
In the first line there is a number T(T≤20), denotes the number of test cases.
In the next T lines, for each line there is a string s(1≤|s|≤105), denotes the input string, all inputs are formed in lowercases.Output
Output T lines, for each line, you need to output ''Case #t: m''(without quotes), where t is the index of this test case, m is the maximum quality you could reach after permuting.
Sample Input
5 abcde sankaranarayanan abbccaabc programming monotone
Sample Output
Case #1: 1 Case #2: 7 Case #3: 3 Case #4: 2 Case #5: 3
题意:题目给了一堆公式看得头疼,直接分析样例可以发现,题目要求的就是字符串中字符出现的最大次数是多少
AC代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int a[30];
int main()
{
int t;
cin>>t;
string s;
for(int k=1;k<=t;k++)
{
memset(a,0,sizeof a);
int res=0;
cin>>s;
for(int i=0;i<s.size();i++)
a[s[i]-'a']++;
for(int i=0;i<27;i++)
res=max(res,a[i]);
printf("Case #%d: %d\n",k,res);
}
}