bzoj1030 [JSOI2007] Text generator

Source: Internet
Author: User

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 Output100

Positive solution: $AC $ automaton + $DP $.

First we construct the $ac$ automata, and record each bit is possible to form a match, is to record each bit of $val$ and $last$ on the line.

Set $f[i][j]$ said statistics to the text before the $i$ bit, the $j$ on the machine, there is no matching scheme number, remove can match the situation, direct vigorously transfer on the line.

Finally, we subtract the number of mismatched scenarios by the total scheme number, that is, there is at least one matching scheme number.

1 //It's made by wfj_2048~2#include <algorithm>3#include <iostream>4#include <complex>5#include <cstring>6#include <cstdlib>7#include <cstdio>8#include <vector>9#include <cmath>Ten#include <queue> One#include <stack> A#include <map> -#include <Set> - #defineRHL (10007) the #defineINF (1&LT;&LT;30) - #defineN (10010) - #defineIl inline - #defineRG Register + #definell Long Long - #defineFile (s) freopen (S ".", "R", stdin), Freopen (S ". Out", "w", stdout) +  A using namespacestd; at  - intf[ the][n],q[n],n,m,len,ans; - CharS[n]; -  - structac_auto{ -  in     intch[n][ -],val[n],nxt[n],last[n],sz; -  toIlvoidInsertChar*s,rgintLen) { +Rgintx=0, C; -      for(RGintI=1; i<=len;++i) { thec=s[i]- $; *         if(!ch[x][c]) ch[x][c]=++sz; $x=Ch[x][c];Panax Notoginseng     } -val[x]++;return; the     } +      AIlvoidbuild () { theRgintH=0, t=0; +      for(RGintC=0;c< -;++c) -         if(ch[0][C]) nxt[ch[0][c]]=last[ch[0][c]]=0, q[++t]=ch[0][c]; $      while(h<t) { $Rgintx=q[++h],v,j; -          for(RGintC=0;c< -;++c) { -V=CH[X][C];if(!V) {Ch[x][c]=ch[nxt[x]][c];Continue; } theq[++t]=v,nxt[v]=last[v]=0, J=nxt[x]; while(J &&!ch[j][c]) j=Nxt[j]; -NXT[V]=CH[J][C],LAST[V]=VAL[NXT[V]]?Nxt[v]: last[nxt[v];Wuyi         } the     } -     return; Wu     } -      About }ac; $  -Ilintgi () { -Rgintx=0, q=1; RgCharCh=GetChar (); -      while((ch<'0'|| Ch>'9') && ch!='-') ch=GetChar (); A     if(ch=='-') q=-1, ch=GetChar (); +      while(ch>='0'&& ch<='9') x=x*Ten+ch- -, ch=GetChar (); the     returnq*x; - } $  theIlintQpow (RGintA,rgintb) { theRgintans=1; the      while(b) { the     if(b&1) ans=ans*a%RHL; -a=a*a%rhl,b>>=1; in     } the     returnans; the } About  theIlvoidWork () { theN=gi (), m=gi (); the      for(RGintI=1; i<=n;++i) { +scanf"%s", s+1); -Len=strlen (s+1); the Ac.insert (S,len);Bayi     } theAc.build (); f[0][0]=1; the      for(RGintI=0; i<m;++i) -      for(RGintj=0; j<=ac.sz;++j) { -         if(!f[i][j])Continue; the          for(RGintk=0;k< -;++k) { the         if(Ac.val[ac.ch[j][k] | | AC.LAST[AC.CH[J][K]])Continue; thef[i+1][ac.ch[j][k]]+=F[i][j]; the         if(f[i+1][AC.CH[J][K]]&GT;=RHL) f[i+1][ac.ch[j][k]]-=RHL; -         } the     } the      for(RGintI=0; i<=ac.sz;++i) {ans+=f[m][i];if(ANS&GT;=RHL) ans-=RHL;} theprintf"%d\n", (Qpow ( -, m)-ans+rhl)%RHL);return;94 } the  the intMain () { theFile ("txt");98 Work (); About     return 0; -}

bzoj1030 [JSOI2007] Text generator

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.