The first time to write this kind of question ... Ignorant
The direct calculation of the answer is not good calculation, so the complement transformation to seek an illegal scheme.
first consider the naïve DP, set $f (I, s) $ to represent the first $i$ characters, the string is $s$ scheme number, and any given string does not exist in $s$.
we know that finding other strings in a string is the strength of AC automata, so we can consider in the AC automaton running DP, each $+j$ in the AC automaton match, if the match to the end of words can not be transferred, otherwise it can be transferred.
So set $f (i, j) $ for the first $i$ characters, the current match to the number of $j$ nodes on the AC automaton, if all the nodes along the fail are not the end of the word can be transferred.
Note the capital letter t_t
#include <iostream>#include<cstring>#include<cstdlib>#include<cstdio>#include<algorithm>#defineMOD (x) ((x) >=mod? ( x)-mod: (x))#definell Long Longusing namespacestd;Const intmaxn=6010, maxm= the, mod=10007;structpoi{intnxt[ -], fail;} tree[maxn*MAXM];intN, M, ans, Tott;intF[MAXM][MAXN], H[MAXN];BOOLCNT[MAXN];CharS[maxm];inlinevoidReadint&k) { intf=1; k=0;CharC=GetChar (); while(c<'0'|| C>'9') c=='-'&& (f=-1), c=GetChar (); while(c<='9'&& c>='0') k=k*Ten+c-'0', c=GetChar (); K*=F; } InlinevoidInsert () {intLen=strlen (s+1), now=0; for(intI=1, ch;i<=len;i++) { if(!tree[now].nxt[ch=s[i]-'A']) Tree[now].nxt[ch]=++Tott; now=Tree[now].nxt[ch]; } Cnt[now]=1;} InlinevoidGetfail () {intFront=1, rear=0; tree[0].fail=-1; for(intI=0, too;i< -; i++) if((too=tree[0].nxt[i]) h[++rear]=too; while(front<=rear) { intnow=h[front++]; for(intI=0, too;i< -; i++) if((too=Tree[now].nxt[i])) Tree[too].fail=tree[tree[now].fail].nxt[i], h[++rear]=too; Elsetree[now].nxt[i]=Tree[tree[now].fail].nxt[i]; Cnt[now]|=Cnt[tree[now].fail]; }}intMain () {read (n); read (m); for(intI=1; i<=n;i++) scanf ("%s", s+1), insert (); Getfail (); f[0][0]=1; for(intI=1; i<=m;i++) for(intj=0; j<=tott;j++) if(!cnt[j]) for(intk=0;k< -; k++) F[i][tree[j].nxt[k]]=mod (f[i][tree[j].nxt[k]]+f[i-1][j]); for(intI=0; i<=tott;i++)if(!cnt[i]) Ans=mod (ans+F[m][i]); inttot=1; for(intI=1; i<=m;i++) tot=1ll*tot* -%MoD; printf ("%d\n", MOD (tot-ans+mod));}
View Code
bzoj1030: [JSOI2007] Text generator (AC automaton +DP)