Bzoj 1030 [JSOI2007] Text generator

Source: Internet
Author: User

1030: [JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
submit:2624 solved:1087
[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 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 Output -HINT Source

Problem: ACDP's entry

The complement transform becomes the number of points that have danger. At first, I always turn the corner, now understand: Nest Meng set a string prefix for the stage of consideration, then what to do at this stage? To "push the one-step automaton" right, then add a dimension to take into account the robot nodes on the line, the concrete implementation of the nest is directly written in the automaton F[m].

And then again this endmark, you can think of TA as a virus, at first in all the End_node, in the Nest Meng Getfail, will follow the received fail pointer spread, and then did not then ... Concrete implementation is in the getfail when the maintenance of the line.

Self-motive or a very magical thing, which day to fill Pam play.

1#include <iostream>2#include <cstdio>3#include <cmath>4#include <algorithm>5#include <stack>6#include <queue>7#include <cstring>8 #definePAU Putchar (")9 #defineENT Putchar (' \ n ')Ten #defineTrans (P) while (P&&!p->tx[c]) p=p->fail;if (!p) p=root; One using namespacestd; A Const intmaxn=10000+Ten, maxnode=10000+Ten, sig= -, inf=-1u>>1, mod=10007; - structnode{ -Node*tx[sig],*fail;intf[ the];BOOLV;node () {v=false; Memset (F,0,sizeof(f)); the}ac[maxnode],*nodecnt=ac,*root=nodecnt++; -node*Get(node*x) {returnX?X:root;} -Node*tran (Node*x,intc) { while(X&&!x->tx[c]) x=x->fail;if(!x) X=root;returnx;} - voidInsertChar*1) { +node*x=Root; -      for(intI=0; s[i];i++){ +         intc=s[i]-'A'; A         if(!x->tx[c]) x->tx[c]=nodecnt++; atX=x->Tx[c]; -}x->v=true;return; - } - voidGetfail () { -queue<node*>q; for(intC=0; c<sig;c++)if(Root->tx[c]) Q.push (root->tx[c]); -      while(!Q.empty ()) { innode*x=Q.front (); Q.pop (); -          for(intC=0; c<sig;c++)if(x->Tx[c]) { toNode*p=tran (x->fail,c); x->tx[c]->fail=Get(p->tx[c]); +             if(P-&GT;TX[C]&AMP;&AMP;P-&GT;TX[C]-&GT;V) x->tx[c]->v=true; Q.push (x->tx[c]); -         } the}return; * } $ voiddpintx) {Panax Notoginseng      for(node*t=ac;t!=nodecnt;t++){ -         if(!t->v&&t->f[x-1]) for(intC=0; c<sig;c++){ theNode*p=tran (T,C);Get(P->tx[c])->f[x]+=t->f[x-1]%=MoD; +         } A}return; the } + CharS[MAXN];intn,m; -InlineintRead () { $     intx=0, sig=1;CharCh=GetChar (); $      for(;! IsDigit (CH); Ch=getchar ())if(ch=='-') sig=0; -      for(; isdigit (ch); Ch=getchar ()) x=Ten*x+ch-'0'; -     returnsig?x:-x; the } -InlinevoidWriteintx) {Wuyi     if(x==0) {Putchar ('0');return;}if(x<0) Putchar ('-'), x=-x; the     intlen=0, buf[ the]; while(x) buf[len++]=x%Ten, x/=Ten; -      for(inti=len-1; i>=0; i--) Putchar (buf[i]+'0');return; Wu } - intMain () { AboutN=read (); M=read ();intans=1, ans2=0; $      for(intI=1; i<=n;i++) scanf ("%s", s), insert (s); -Getfail (); root->f[0]=1; -      for(intI=1; i<=m;i++) DP (i), ans=ans* -%MoD; -      for(node*t=ac;t!=nodecnt;t++)if(!T-&GT;V) (Ans2+=t->f[m])%=MoD; AWrite ((ans-ans2+mod)%MoD); +     return 0; the}

Bzoj 1030 [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.