Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string.
Then Borya came and said that the new string contained a tandem repeat of length l as a substring. How large could l be?
See notes for definition of a tandem repeat.
The first line contains s (1 ≤ |s| ≤ 200). This string contains only small English letters. The second line contains number k (1 ≤ k ≤ 200) — the number of the added characters.
Print a single number — the maximum length of the tandem repeat that could have occurred in the new string.
aaba 2
6
aaabbbb 2
6
abracadabra 10
20
A tandem repeat of length 2n is string s, where for any position i (1 ≤ i ≤ n) the following condition fulfills: si = si + n.
In the first sample Kolya could obtain a string aabaab, in the second — aaabbbbbb, in the third — abracadabrabracadabra.
比赛的时候,题目意思没看懂,理解错误,一直没做出来,真是悲剧。外语水平太差了。
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
char str[3333];
int fla[999];
int main(void)
{
int i,j,n,m,k,maxx=-1;
gets(str);
cin>>k;
int len=strlen(str);
if(k>=len)
printf("%d\n",(k+len)/2*2);
else
{
n=len+k;
for(i=0;i<len;i++)
{
for(j=1;j<=len-i;j++)
{
int ans=0;
for(int kk=i;kk<i+j;kk++)
{
if(kk+j>=len&&kk+j<n)
ans++;
else if(str[kk]==str[kk+j])
ans++;
}
if(ans==j)//这里之前忘了写了。。。
maxx=max(ans,maxx);
}
}
cout<<maxx*2<<endl;
}
return 0;
}