Always do not understand how to do ah, think for a long time $twt$
Finally understand why find the first $fail$ to meet the criteria to calculate, because avoid repetition, this answer,,,
Then $root$ below to connect to 26 nodes, here 26 letters are not in the dictionary is replaced with $f[i][0]$, this also thought for a long time, $==$ I still go Home farm.
#include <cstdio> #include <cstring> #include <algorithm> #define MO 10007#define N 103#define M 6003using namespace Std;int q[m], c[m][26], w[m], fail[m], f[n][m], N, M, cnt = 0;inline void ins (char *s) {int len = Strl En (s), now = 0;for (int i = 0; i < len; ++i) {int t = s[i]-' A '; if (!c[now][t]) c[now][t] = ++cnt;now = C[now][t];} W[now] = 1;} inline void BFS () {int head = 0, tail = 1, now = 0;q[1] = 0;while (head! = tail) {now = q[++head];for (int t = 0; t < 26 ; ++t) if (C[now][t]) {Q[++tail] = c[now][t];if (now = = 0) continue;int tmp = fail[now];while (tmp &&!c[tmp][t]) tmp = Fail[tmp];fail[c[now][t]] = C[tmp][t];if (W[c[tmp][t]]) w[c[now][t]] = 1; //!!!!!!!}}} inline int Ipow (int x, int nn) {int ans = 1;for (int t = x; nn; nn >>= 1, t = (t * t)% mo) if (NN & 1) {ans = (an S * t); if (ans >= mo) ans = ans% mo;} return ans;} inline void AC () {f[0][0] = 1;for (int i = 0; I <= m; ++i) for (int j = 0; J <= CNT, ++j) if (F[i][j]) {for (int t = 0; t < 26; ++T) {int tmp = J;WHILE (tmp &&!c[tmp][t]) tmp = FAIL[TMP];TMP = C[tmp][t];if (!w[tmp]) {f[i + 1][tmp] + = F[i][j];i F (f[i + 1][tmp] >= mo) f[i + 1][tmp]%= mo;}}} int _ = 0, Al = Ipow (+, M), for (int i = 0; I <= cnt; ++i) if (!w[i]) {_ + = F[m][i];if (_ > Mo) _%= mo;} int ans = ((al-_)% mo + mo)%mo;printf ("%d\n", ans); int main () {scanf ("%d%d", &n, &m), char s[n];for (int i = 1; I <= n; ++i) scanf ("%s", s), ins (s); BFS (); AC (); return 0;}
Finally made it out, because looking at someone else's template, which also,,,
"Bzoj 1030" "Jsoi 2007" text generator ac automata + recursive