1030: [JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
submit:1902 solved:776
[Submit] [Status] 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 indicate the number of readable text in all the text generated by the GW text Generator V6 so that the V7 update can be successfully obtained. Can you help him?
Input
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
An integer that represents the total number of possible articles. You only need to know the value of the result modulus 10007.
Sample Input2 2
A
BSample Output -The following:
(Xue) to acquire AC automata.
Some comments are written in the code.
Code:
1#include <cstdio>2 3#include <cstdlib>4 5#include <cmath>6 7#include <cstring>8 9#include <algorithm>Ten One#include <iostream> A -#include <vector> - the#include <map> - -#include <Set> - +#include <queue> - +#include <string> A at #defineINF 1000000000 - - #defineMAXN 1000000+5 - - #defineMAXM 20000000+5 - in #defineEPS 1e-10 - to #definell Long Long + - #definePA pair<int,int> the * #defineFor0 (i,n) for (int i=0;i<= (n); i++) $ Panax Notoginseng #defineFor1 (i,n) for (int i=1;i<= (n); i++) - the #defineFor2 (i,x,y) for (int i= (x); i<= (y); i++) + A #defineFor3 (i,x,y) for (int i= (x); i>= (y); i--) the + #defineMoD 10007 - $ using namespacestd; $ -InlineintRead () - the { - Wuyi intx=0, f=1;CharCh=GetChar (); the - while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} Wu - while(ch>='0'&&ch<='9') {x=Ten*x+ch-'0'; ch=GetChar ();} About $ returnx*F; - - } - intt[6010][ -],f[ the][6010][2],v[6010],go[6010]; A Chars[ the]; +queue<int>Q; the intN,m,tot; -InlinevoidInsert () $ { thescanf"%s", s+1);intLen=strlen (s+1), now=1; the For1 (I,len) the { the intx=s[i]-'A'; - if(!t[now][x]) t[now][x]=++tot; innow=T[now][x]; the } thev[now]=1;//flag The node as a dangerous node About } the voidBFS ()//the fail of each node is recursively pushed by the BFS sequence, represented here with the Go array the { theQ.push (1); + while(!q.empty ()) - { the intx=Q.front (), Y,j;q.pop ();BayiFor0 (I, -) the { thej=Go[x]; - while(J&&!t[j][i]) j=Go[j]; - if(T[x][i]) the { theGo[y=t[x][i]]=j?t[j][i]:1;//the node exists then sets its fail theV[y]=v[y]|v[go[y]];//It's dangerous symbols theQ.push (y);//fail to update its subtree -}ElseT[x][i]=j?t[j][i]:1;//there's no straight out side . the } the } the }94 voidDP () the { thef[0][1][0]=1; the for0 (i,m)98 For1 (J,tot) AboutFor0 (k, -) -For0 (L,1)//L = match or no match101 if(V[t[j][k]]) (f[i+1][t[j][k]][1]+=F[I][J][L])%=MoD;102 Else(f[i+1][T[J][K]][L]+=F[I][J][L])%=MoD;103 }104 the intMain ()106 107 {108 109Freopen ("Input.txt","R", stdin); the 111Freopen ("output.txt","W", stdout); the 113N=read (); M=read (); tot=1; the For1 (i,n) insert (); the BFS (); the DP ();117 intans=0;118For1 (I,tot) (ans+=f[m][i][1])%=MoD;119printf"%d\n", ans); - 121 return 0;122 123}
View Code
BZOJ1030: [JSOI2007] Text generator