CF 535D Next Array

Source: Internet
Author: User

An original string, an unknown string, each time from Pos[i] overwrites the unknown string, asks the last string form, and determines whether there is a contradiction in the process.

POS is ascending in the process, so if the coverage does not overlap, then it is OK to determine whether a suffix of the original string is also a prefix. This can be computed with next array, z function, suffix array, and so on.

1#include <iostream>2#include <vector>3#include <algorithm>4#include <string>5#include <string.h>6#include <stdio.h>7#include <math.h>8#include <stdlib.h>9#include <queue>Ten#include <stack> One#include <map> A#include <Set> -  - using namespacestd; the  - Const intn=1e6+12345; - CharS[n]; - BOOLValid[n]; + intNext[n]; - voidGetNext (Char*word,intn=0){ +N= (n==0)?strlen (Word): n; AMemset (Next,0,sizeof(next)); at     inti,j; -      for(i=1; i<n;i++){ -j=i; -          while(j) { -j=Next[j]; -             if(word[i]==Word[j]) { innext[i+1]=j+1; -                  Break; to             } +         } -     } the } * intPos[n]; $ intMain () {Panax Notoginseng     intn,c; -scanf"%d%d",&n,&c); thescanf"%s", s); +     intm=strlen (s); A GetNext (s,m); the      for(intI=m;i;i=Next[i]) +valid[i]=true; -      for(intI=1; i<=c;i++) $scanf"%d", pos+i); $pos[0]=-m;pos[++c]=n+1; -     intSpace=0; -     BOOLok=true; the      for(intI=1; i<=c;i++) { -pos[i]--;Wuyi         if(pos[i-1]+m>Pos[i]) { the             if(!valid[m-pos[i]+pos[i-1]]) -ok=false; Wu         } -         Else { Aboutspace+=pos[i]-(pos[i-1]+m); $         } -     } -     if(!OK) -cout<<0<<Endl; A     Else { +         Long Longret=1; the          for(intI=1; i<=space;i++) -ret=ret*26ll%1000000007; $cout<<ret<<Endl; the     } the     return 0; the}
View Code

CF 535D Next Array

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.