1030: [JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
http://www.lydsy.com/JudgeOnline/problem.php?id=1030
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 -ans=26^m-does not contain the number of any one template stringdoes not contain the number of any one template string,routine Dp[i][j] left I no fill, currently in the AC Automaton J-node
#include <queue>#include<cstdio>#include<cstring>#defineMoD 10007using namespacestd;intn,m,len,id,root,tot=1;intf[ A*101],trie[ A*101][ -];Chars[101];BOOLmark[ A*101];intdp[101][ A*101];BOOLv[101][ A*101];queue<int>Q;structacautomata{voidInsert () {len=strlen (s); Root=1; for(intI=0; i<len;i++) {ID=s[i]-'A'; if(!trie[root][id]) trie[root][id]=++tot; Root=Trie[root][id]; } Mark[root]=true; } voidGetfail () { for(intI=0;i< -; i++) trie[0][i]=1; Q.push (1); intnow,j; while(!Q.empty ()) { Now=Q.front (); Q.pop (); for(intI=0;i< -; i++) { if(!Trie[now][i]) {Trie[now][i]=Trie[f[now]][i]; Continue; } q.push (Trie[now][i]); J=F[now]; F[trie[now][i]]=Trie[j][i]; if(Mark[trie[j][i]]) mark[trie[now][i]]=true; } } } intDfsintLintNow ) { if(!l)return 1; if(V[l][now])returnDp[l][now]; V[l][now]=true; for(intI=0;i< -; i++) if(!mark[trie[now][i]]) dp[l][now]= (Dp[l][now]+dfs (l1, Trie[now][i]))%MoD; returnDp[l][now]; }}; Acautomata AC;intMain () {scanf ("%d%d",&n,&m); while(n--) {scanf ("%s", s); Ac.insert (); } ac.getfail (); intA=ac.dfs (M,1); intb=1; for(intI=1; i<=m;i++) b=b* -%MoD; printf ("%d", (b-a+mod)%mod);}
[JSOI2007] Text generator