HDU 6894 CCPC Training Class

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);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Double.Qing

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值