CodeForces

来源:互联网 发布:linux vim 删除 编辑:程序博客网 时间:2024/06/08 10:06

You will receive 5 points for solving this problem.

Manao has invented a new operation on strings that is called folding. Each fold happens between a pair of consecutive letters and places the second part of the string above first part, running in the opposite direction and aligned to the position of the fold. Using this operation, Manao converts the string into a structure that has one more level than there were fold operations performed. See the following examples for clarity.

We will denote the positions of folds with '|' characters. For example, the word "ABRACADABRA" written as "AB|RACA|DAB|RA" indicates that it has been folded three times: first, between the leftmost pair of 'B' and 'R' letters; second, between 'A' and 'D'; and third, between the rightmost pair of 'B' and 'R' letters. Here are several examples of folded strings:

"ABCDEF|GHIJK" |  "A|BCDEFGHIJK" |  "AB|RACA|DAB|RA" |  "X|XXXXX|X|X|XXXXXX"               |                 |                   |       XXXXXX    KJIHG      |   KJIHGFEDCB    |      AR           |       X   ABCDEF      |            A    |     DAB           |       X               |                 |     ACAR          |       XXXXX               |                 |       AB          |           X

One last example for "ABCD|EFGH|IJ|K":

 KIJHGFEABCD

Manao noticed that each folded string can be viewed as several piles of letters. For instance, in the previous example, there are four piles, which can be read as "AHI", "BGJK", "CF", and "DE" from bottom to top. Manao wonders what is the highest pile of identical letters he can build using fold operations on a given word. Note that the pile should not contain gaps and should start at the bottom level. For example, in the rightmost of the four examples above, none of the piles would be considered valid since each of them has gaps, starts above the bottom level, or both.

Input

The input will consist of one line containing a single string of n characters with 1 ≤ n ≤ 1000 and no spaces. All characters of the string will be uppercase letters.

This problem doesn't have subproblems. You will get 5 points for the correct submission.

Output

Print a single integer — the size of the largest pile composed of identical characters that can be seen in a valid result of folding operations on the given string.

Example
Input
ABRACADABRA
Output
3
Input
ABBBCBDB
Output
3
Input
AB
Output
1
Note

Consider the first example. Manao can create a pile of three 'A's using the folding "AB|RACAD|ABRA", which results in the following structure:

ABRADACAR   AB

In the second example, Manao can create a pile of three 'B's using the following folding: "AB|BB|CBDB".

CBDBBBAB

Another way for Manao to create a pile of three 'B's with "ABBBCBDB" is the following folding: "AB|B|BCBDB".

 BCBDB BAB

In the third example, there are no folds performed and the string is just written in one line.


 【题解】  这题乍一看一脸懵比,又是折叠又是字符串一通乱搞,完全不知道它在说什么,静下心来想一想,把题目意思再细细品味一下,会发现,它要在给定的字符串里找到几个可以插入隔板的位置,这些隔板把隔板左右分割开,设隔板的位置为 i ,分割后的字符串两端要对称,是最左边和最右边对称,不是两边所有字符完全对称,比如样例1,ABRACADABRA ,在第一个B和R中间插入板子,可以使两个A对称,那么就可以满足,然后再在最后面的AB和RA之间插入板子,可以让其对称,(你或许会想在第四个A后面插个板子也可以把最后6个字符对称,但是请注意,最后四个字符已经用过了,最后一个A要和倒数第二个A对称,所以就不可能和倒数第三个A做对称了),相信现在你应该明白这题的意思了吧,出题人真是用心良苦啊,哈哈,所以思路就是从前往后每次标记一个位置,然后从下一个位置开始,每次隔一个点,判断它是不是和标记点字符一样,一样的话就可以构成对称,遍历一遍后,找到最大值即可,

 

ps:所有的点初始化都是1,即刚开始都只有当前点自身,我在代码中初始化为0,但在结果处加了1,具体看代码;


 【AC代码】

 

#include<iostream>#include<cstdio>#include<algorithm>#include<cstring>using namespace std;int main(){    int dp[100000],ans;    char s[1005];    while(~scanf("%s",s))    {        ans=0;        memset(dp,0,sizeof(dp));        int len=strlen(s);        for(int i=0;i<len-1;++i)        for(int j=i+1;j<len;j+=2){            if(s[i]==s[j])                dp[j]=dp[i]+1;            ans=max(ans,dp[j]);        }        printf("%d\n",ans+1);    }    return 0;}