Codeforces 443B Kolya and Tandem Repeat

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.