1030: [JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
submit:4859 solved:2019
[Submit] [Status] [Discuss] Description
Jsoi to the players zgx a task, the production of a "text generator" computer software: The user of the software is some battleship dogs,
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?. ZGX 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 -Idea {ac automaton bare topic. but for an AC automaton like me, I never brushed it.It's still harder to match the spicy chicken. definitely think of is DP, how to set the state! we should make it clear that God is the horse. The number of direct solutions is not. that can also be the total number of cases minus the number of failed scenarios. we would like to have a target serial word up to the point of the AC automaton at the end of the previous one, or a fail chain before the point. and the target string only walk m step! Just DP ~ ~ ~ ~Dp[i][k] Indicates the number of scenarios that match the I-step to K-pointthat transfer equation: dp[i][ch[k][j]]+=dp[i-1][k];Yes, ~~~~~~~~~~~.}
#include <bits/stdc++.h> #define RG register#define il inline#define N 60010using namespace Std;int ch[n][27],f[n], Cc,n,k;char s[n*2];bool in[n];void Insert () {int Now=0,len=strlen (s+1); int h=1; while (h<=len) {int c=s[h]-' A '; if (!ch[now][c]) ch[now][c]=++cc; now=ch[now][c];h++; }in[now]=true;} Il void Getfail () {queue<int>que; while (!que.empty ()) Que.pop (); Que.push (0); while (!que.empty ()) {RG int u=que.front (); for (RG int i=0;i<26;++i) {if (Ch[u][i]) Que.push (Ch[u][i]), f[ch[u][i]]= (U==0?0:ch[f[u]][i]); else ch[u][i]= (U==0?0:ch[f[u]][i]); } In[u]|=in[f[u]]; Que.pop (); }return;} #define MOD 10007int qpow (int a,int b) {if (b==1) return a;if (!b) return 1; int Tmp=qpow (A, (b>>1)); tmp= (tmp*tmp)%mod;if (b&1) tmp= (tmp*a)%mod; return TMP;} int Dp[101][n];int Main () {freopen ("1.in", "R", stdin); Freopen ("1.out", "w", stdout); scanf ("%d%d", &n,&k); for (int i=1;i<=n;++i) scanf ("%s", s+1), Insert (); Getfail (); Dp[0][0]=1; for (int i=1;i<=k;++i) for (int j=0;j<=cc;++j) if (!in[j]) {for (int k=0; K<26;++K) {dp[i][ch[j][k]]+=dp[i-1][j]; if (Dp[i][ch[j][k]]>=mod) dp[i][ch[j][k]]-=mod;} }int Ans=qpow (26,k); for (int i=0;i<=cc;++i) if (!in[i]) ans-= (dp[k][i]%mod), ans= (Ans+mod)%mod; cout<<ans; return 0;}
BZOJ1030:[JSOI2007] Text Generator