##__VA_ARGS__)#else#definedebug(...)void(0)#endiftypedeflonglongLL;intn,m,z[1<<26];chara[1<<26];voidexkmp(intlen){z[1]=len;debug("a = %s\n",a+1);for(inti=2,l=0,r=0;i<=len;i++){if(i<=r)z[i]=min(
z[1] = n;intl =0,r =0;for(inti =2; i <= n; i++) {if(i <= r) z[i] =min(z[i-l+1],r-i+1);while(i+z[i] <= n && s[i+z[i]] == s[1+z[i]]) z[i]++;if(i+z[i]-1> r) l = i, r = i+z[i]-1; } }voidexkmp(char*s,char*t,intn){intl =0,...
for(int i=1;i<=len;++i) z[i]=0; z[1]=len; for(int i=2,l=0,r=0;i<=len;++i) { if(i<=r) z[i]=min(z[i-l+1],r-i+1); for(;i+z[i]<=len&&s[i+z[i]]==s[z[i]+1];++z[i]); if(i+z[i]-1>r) l=i,r=i+z[i]-1; } } void exkmp(char *s,int ...
//#include<bits/stdc++.h> #include<iostream>#include<cstdio>#include<ctime>#include<cctype>#include<queue>#include<deque>#include<stack>#include<iostream>#include<iomanip>#include<cstdio>#include<cstring>#include<string>#include<ctime>#include<cmath>#include<cctype>#include<cstdlib>#include<queu...
需要提前预处理出 P 的z 函数。代码:void exkmp(char *T, char *P) { int n = strlen(T) - 1, m = strlen(P) - 1; // 同上,注意这里 n 和 m 就是分别实际的文本串和模式串的长度 for (int i = 1, k = 0; i <= n; ++i) { // 注意哪些地方换成了 p(也就是刚刚我说的 e),...
z函数即exkmp 对于一个长度为nn的字符串ss,定义函数z[i]z[i]表示ss和s[i,n−1]s[i,n−1]的的最长公共前缀长度,注意后面算法求z函数时特定z[0]=0z[0]=0 算法流程:主要核心在求z[i]z[i]时要利用前面z[0],z[1],…,z[i−1]z[0],z[1],…,z[i−1]的信息,从i=1i=1开始,对于...
void exkmp(char *s,int n,char *t,int m) { Z(t,m); for(int i=1;i<=n;++i) p[i]=0; for(int i=1,l=0,r=0;i<=n;++i) { if(i<=r) p[i]=min(z[i-l+1],r-i+1); for(;i+p[i]<=n&&s[i+p[i]]==t[p[i]+1];++p[i]); if...
{if(i+nex[i-p0]-1<nex[p0]+p0-1)nex[i]=nex[i-p0];else{intnow=max(0,nex[p0]+p0-i);while(T[now]==T[i+now]&&i+now<tl)++now; nex[i]=now;p0=i; } } }inlinevoidexkmp(){getnex();intnow=0,p0=0,ww=min(sl,tl);while(S[now]==T[now]&&now<ww)++now; ...