Title: Click Here
Test instructions: Given a string (containing only lowercase letters and a maximumof five) and an n (which means that you can add n (<=200) characters to any given string). Ask the longest substring length, the substring satisfies the first half equals the second half .
Analysis: Violent ~~~~~~
#include <bits/stdc++.h>using namespaceStd;typedefLong Longll;Const intINF =0x3f3f3f3f;Const intM = 3e5+3;intK;CharStr[m];intans, Len, lenth;BOOLCheckintXintY) {//determine if [x, Y] and [y+1,y-x+1] are the same in a string if(x >= len)return true; for(intI=x; i<=y; i++ ) { if(I+lenth >= Len) Break; if(Str[i]! = Str[i+lenth])return false; } return true;}voidsolve () {Len=strlen (str); Ans=0; for(intI=0; i<len+k-1; i++ ) { for(intJ=i; j<len+k; J + +) {Lenth= j+1-i; if(J+lenth >= len+k) Break; if(Lenth <= ans)Continue; if(Check (i, J)) ans=Max (ans, lenth); if(ans = = (len+k)/2)return; } }}intMain () { while(~SCANF ("%s%d", str, &k)) {solve (); printf ("%d\n", ans*2 ); } return 0;}
Codeforces 443B Kolya and Tandem Repeat