[NOI 2014]动物园
思路:
比较单纯的求一下next数据和失配的次数。
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MaxN = 1000005;
const int M = 1000000007;
char s[MaxN];
int dep[MaxN], fail[MaxN];
int main()
{
int nT;
scanf("%d", &nT);
while (nT--)
{
scanf("%s", s + 1);
int u = 0, v = 0;
int res = dep[1] = 1;
for (int i = 2; s[i]; ++i)
{
while (u && s[i] != s[u + 1])
u = fail[u];
fail[i] = (u += s[i] == s[u + 1]);
dep[i] = dep[u] + 1;
while (v && s[i] != s[v + 1])
v = fail[v];
v += s[i] == s[v + 1];
while (v > i >> 1)
v = fail[v];
res = (ll)res * (dep[v] + 1) % M;
}
printf("%d\n", res);
}
return 0;
}