1030: [JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
submit:5355 solved:2213
[Submit] [Status] [Discuss] 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 version V6. The software can generate a number of random articles---always generate a fixed length and completely random text
Chapter-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). However, even following such a
Standard, the article generated by the V6 version of the GW text generator used by the user is also 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 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 generated text
Set length m; The following n rows, each containing a word that the user understands. All words and text will not be more than 100 in length and may only be wrapped
Capital letter A, with English. 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 -
/*AC Automaton +DP This problem is difficult to implement if considered legal, so it is less illegal to use the total number. F[I][J] means that the string is filled in the first, and the number of program J is filled in the AC automaton. */#include<iostream>#include<cstdio>#include<cstring>#include<queue>#defineMoD 10007#defineMAXN 6010using namespacestd;intn,m,sz=1, ans1,ans2=1;inta[maxn][ -],fail[maxn],q[maxn],f[101][MAXN],WORD[MAXN];Chars[101];voidInsert () {intnow=1, len=strlen (s); for(intI=0; i<len;i++){ intt=s[i]-'A'+1; if(!a[now][t]) a[now][t]=++sz; now=A[now][t]; } Word[now]=1;}voidAcmach () {Queue<int>Q; Q.push (1); fail[1]=0; while(!Q.empty ()) { intnow=Q.front (); Q.pop (); for(intI=1; i<= -; i++){ if(!a[now][i])Continue; intk=Fail[now]; while(!a[k][i]) k=Fail[k]; Fail[a[now][i]]=A[k][i]; if(Word[a[k][i]]) word[a[now][i]]=1;//WhyQ.push (A[now][i]); } }}voiddpintx) { for(intI=1; i<=sz;i++) {//Enumerate each node on the AC automaton if(word[i]| |! f[x-1][i])Continue;//Word[i] is even a word,!f[x-1][i] is the last time no match on for(intj=1; j<= -; j + +){ intK=i;//The last point that was matched to while(!a[k][j]) k=fail[k];//find a fail pointer that can point to the letter JF[x][a[k][j]]= (f[x][a[k][j]]+f[x-1][i])%MoD; } }}intMain () {scanf ("%d%d",&n,&m); for(intI=1; i<= -; i++) a[0][i]=1; for(intI=1; i<=n;i++) {scanf ("%s", s); Insert (); } Acmach (); f[0][1]=1; for(intI=1; i<=m;i++) DP (i); for(intI=1; i<=m;i++) ans2= (ans2* -)%MoD; for(intI=1; i<=sz;i++) if(!word[i]) ans1= (Ans1+f[m][i])%MoD; printf ("%d", (ans2-ans1+mod)%MoD); return 0;}
Bzoj 1030: [JSOI2007] Text generator