Title Description
Jsoi to the players zyx a task, the production of a "text generator" computer software: The user of the software is some low-young people, they are now using the GW Text Generator V6 version.
The software can generate some random articles----always generate a fixed length and completely random article--that is, every byte in the generated article is completely random. If an article contains at least one word that the user understands, then we say this article is readable (we call the article A contains the word B when and only if the word b is a substring of article a). But even by this standard, the V6 version of the GW text generator that the user is using now is almost completely unreadable. ZYX need to point out the GW text generator V6
The number of readable text in all generated text so that the V7 update can be successfully obtained. Can you help me?
Input/output format
Input format:
The first line of the input file contains two positive integers, the total number of words that the user understands (<=), and the GW text generator v6 The resulting text fixed length m; The following n lines, each containing a word that the user understands. All words and text will not be longer than 100 and may contain only capital letters a. Z
Output format:
An integer that represents the total number of possible articles. You only need to know the value of the result modulus 10007.
Input and Output sample input sample #: Copy
2 2AB
Output Example # #: Replication
100
F[I][J] indicates that the article length is I, in the AC automaton position for J No Word scheme number
And the answer is 26m-∑f[m][]
The transfer is going down from the AC automaton.
F[I+1][CH[J][K]]+=F[I][J] (Ch[j][k] position not marked)
Pay attention to the handling of the AC automatic machine, handling the included situation
VAL[X]|=VAL[FAIL[X]]
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5#include <cmath>6#include <queue>7 using namespacestd;8queue<int>Q;9 intch[10010][ -],f[ the][10010],size,val[10010],fail[10010],n,m,mod=10007, ans;Ten Chars[ the]; One intQpow (intXinty) A { - intres=1; - while(y) the { - if(y&1) res=1ll*res*x%Mod; -x=1ll*x*x%Mod; -y>>=1; + } - returnRes; + } A voidInsertintlen) at{inti; - intnow=0; - for(i=0; i<len;i++) - { - if(ch[now][s[i]-'A']==0) -ch[now][s[i]-'A']=++size; innow=ch[now][s[i]-'A']; - } toval[now]=1; + } - voidAc_build () the{inti; * for(i=0;i< -; i++) $ if(ch[0][i])Panax Notoginsengfail[ch[0][i]]=0, Q.push (ch[0][i]); - while(Q.empty () = =0) the { + intu=Q.front (); A Q.pop (); the for(i=0;i< -; i++) + { - if(Ch[u][i]) fail[ch[u][i]]=Ch[fail[u]][i],q.push (Ch[u][i]); $ Elsech[u][i]=Ch[fail[u]][i]; $ if(Val[fail[u]]) -val[u]=Val[fail[u]]; - } the } - }Wuyi intMain () the{intI,j,k,len; -Cin>>n>>m; Wu for(i=1; i<=n;i++) - { Aboutscanf"%s", s); $len=strlen (s); - Insert (len); - } - ac_build (); Af[0][0]=1; + for(i=0; i<m;i++) the { - for(j=0; j<=size;j++) $ if(f[i][j]&&val[j]==0) the { the for(k=0;k< -; k++) the { thef[i+1][ch[j][k]]+=F[i][j]; - if(f[i+1][CH[J][K]]>=MOD) f[i+1][ch[j][k]]-=Mod; in } the } the } About for(i=0; i<=size;i++) the if(val[i]==0) the { theans+=F[m][i]; + if(Ans>=mod) ans-=Mod; - } thecout<< (Qpow ( -, m)-ans+mod)%Mod;Bayi}
[JSOI2007] Text generator