Bzoj 3620 seems to have seen in a Dream (KMP)

Source: Internet
Author: User

"Topic link"

http://www.lydsy.com/JudgeOnline/problem.php?id=3620

Test instructions

Given a string, count the number of substrings such as A+b+a, which requires a>=k,b>=1.

Ideas

Enumerates the left endpoint I, the string s[i: N] Statistical answer.

Place a pointer, and then enumerate right endpoint J, if the pointer exceeds half the length, look forward along the fail and set the pointer to K. If the match satisfies the s[i. K]==S[J-K+1..J], finally determine the length limit.

Code

1#include <cstdio>2#include <cstring>3 using namespacestd;4 5typedefLong Longll;6 Const intN = 2e4+Ten;7 8 intn,k;9 ll ans;Ten  One intF[n]; A CharS[n]; -  - voidKMP (Char*s) { the     intN=strlen (s+1); -     intj=0, now=0; -      for(intI=2; i<=n;i++) { -          while(j&&s[j+1]!=s[i]) j=F[j]; +         if(s[j+1]==s[i]) J + +; -f[i]=J; +          A          while(now&&s[now+1]!=s[i]) now=F[now]; at         if(s[now+1]==s[i]) now++; -          while(2*now>=i) now=F[now]; -         if(now>=k) ans++;  -     } - } - intMain () in { -scanf"%s%d", s+2,&K); to     intN=strlen (s+2); +      for(intI=1; i<=n;i++) KMP (s+i); -printf"%lld\n", ans); the     return 0; *}

Bzoj 3620 seems to have seen in a Dream (KMP)

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.