题意
求不相交前后缀匹配数量。
思路
注意本题求的是数量,不是长度。
代码
#include <bits/stdc++.h>
using namespace std;
namespace StandardIO {
template<typename T> inline void read (T &x) {
x=0;T f=1;char c=getchar();
for (; c<'0'||c>'9'; c=getchar()) if (c=='-') f=-1;
for (; c>='0'&&c<='9'; c=getchar()) x=x*10+c-'0';
x*=f;
}
template<typename T> inline void write (T x) {
if (x<0) putchar('-');
if (x>=10) write(x/10);
putchar(x%10+'0');
}
}
using namespace StandardIO;
namespace Solve {
const int N=1000100;
const int MOD=1000000007;
int n,m,ans;
char s[N];
int next[N],num[N];
inline void MAIN () {
read(n);
while (n--) {
scanf("%s",s+1),m=strlen(s+1),ans=1,num[1]=1;
for (register int i=2,j=0; i<=m; ++i) {
while (j&&s[j+1]!=s[i]) j=next[j];
if (s[j+1]==s[i]) ++j;
next[i]=j,num[i]=num[j]+1;
}
for (register int i=1,j=0; i<=m; ++i) {
while (j&&s[j+1]!=s[i]) j=next[j];
if (s[j+1]==s[i]) ++j;
while (j>i/2) j=next[j];
ans=(1ll*ans*(num[j]+1))%MOD;
}
write(ans),putchar('
');
}
}
}
int main () {
// freopen(".in","r",stdin);
// freopen(".out","w",stdout);
Solve::MAIN();
}