Portal: http://www.lydsy.com/JudgeOnline/problem.php?id=1030
[JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
submit:4704 solved:1960
[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 -
Satisfied with the bad, we can seek the total solution-not satisfied with the number.
We set the hair f[i][j] to represent the answer to the I step, matching to the AC automaton section J nodes.
1#include <cstdio>2#include <cstring>3 #defineMoD 100074 Charstr[ -];5 inta[6005][ -],point[6004],q[6555],sz=1;6 BOOLdanger[6004];7 intf[ -][6030];8 intn,m;9 voidins () {Ten intnow=1, C; One intlen=strlen (str); A for(intI=0; i<len;i++){ - intk=str[i]-'A'+1; - //printf ("%d\n", k); the if(A[now][k]) now=A[now][k]; - Elsenow=a[now][k]=++sz; - } -danger[now]=1; + } - voidACM () { + for(intI=1; i<= -; i++) a[0][i]=1; A intL=0, r=0; atpoint[1]=0; q[r++]=1; - while(l<R) { - intnow=q[l++]; - for(intI=1; i<= -; i++){ - if(!a[now][i])Continue; - intk=Point[now]; in while(!a[k][i]) k=Point[k]; -point[a[now][i]]=A[k][i]; todanger[a[now][i]]|=Danger[a[k][i]]; +q[r++]=A[now][i]; - } the } * } $ voiddpintx) {Panax Notoginseng for(intI=1; i<=sz;i++){ - if(Danger[i])Continue; the for(intj=1; j<= -; j + +){ + intk=i; A while(!a[k][j]) k=Point[k]; theF[x][a[k][j]]= (f[x][a[k][j]]+f[x-1][i])%MoD; + } - } $ } $ intMain () { - intans1=0, ans2=1; -scanf"%d%d",&n,&m); the for(intI=1; i<=n;i++){ -scanf"%s", str);Wuyi ins (); the } - ACM (); Wuf[0][1]=1; - for(intI=1; i<=m;i++) DP (i); About $ for(intI=1; i<=m;i++) Ans2 = (ans2* -)%MoD; - - for(intI=1; i<=sz;i++){ - if(!Danger[i]) { AANS1 = (Ans1+f[m][i])%MoD; + } the } - $printf"%d", (ans2-ans1+mod)%MoD); the return 0; the}
[Bzoj 1030] [JSOI2007] Text generator