"bzoj1030" [JSOI2007] Text generator

Source: Internet
Author: User
Tags mul

1030: [JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
submit:3797 solved:1553
[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 -" The Puzzle"first find out the total number of impossible articles, and then cut down on the line. Build an AC automaton, and then do dp,f[i][j on the AC automaton] indicates the current length of I, matching the number of scenarios to the J node of the AC automaton. F[I][TEMP]=F[I][TEMP]+F[I-1][J] (temp is the next node to which the J node is matched)
1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <ctime>6#include <cmath>7#include <algorithm>8 using namespacestd;9 #defineMAXN 110Ten #defineMoD 10007 One structnode{intv,fail,link[ -];} tr[maxn* -]; A intN,m,len,ans,mul (1), q[maxn* -],f[maxn][maxn* -]; - CharCH[MAXN]; -InlineintRead () the { -     intx=0, f=1;CharCh=GetChar (); -      while(!isdigit (CH)) {if(ch=='-') f=-1; Ch=GetChar ();} -      while(IsDigit (CH)) {x=x*Ten+ch-'0'; Ch=GetChar ();} +     returnx*F; - } + voidInsertintKintx) A { at     intdex=ch[k]-'A'; -     if(!tr[x]. Link[dex]) tr[x]. link[dex]=++Len; -     inty=Tr[x]. Link[dex]; -     if(K==strlen (ch+1)) {tr[y].v++;return;} -Insert (k +1, y); - } in voidbuild () - { to     intHead=0, tail=1; +      while(++head<=tail) -     { the         intx=Q[head]; *          for(intI=0;i< -; i++) $             if(Tr[x]. Link[i])Panax Notoginseng             { -                 inty=Tr[x]. Link[i]; theq[++tail]=y; +                 if(!x)Continue; A                 inttemp=Tr[x].fail; the                  while(Temp&&!tr[temp]. Link[i]) temp=Tr[temp].fail; +Tr[y].fail=Tr[temp]. Link[i]; -                 if(Tr[tr[temp]. LINK[I]].V) tr[y].v=1; $             } $     } - } - voidDP () the { -f[0][0]=1;Wuyi      for(intI=1; i<=m;i++) the          for(intj=0; j<=len;j++) -             if(f[i-1][j]&& (!tr[j].v)) Wu                  for(intk=0;k< -; k++) -                 { About                     inttemp=J; $                      while(Temp&&!tr[temp]. LINK[K]) temp=Tr[temp].fail; -temp=Tr[temp]. LINK[K]; -                     if(!TR[TEMP].V) f[i][temp]= (f[i][temp]+f[i-1][J])%MoD; -                 } A } + intMain () the { -     //freopen ("cin.in", "R", stdin); $     //freopen ("Cout.out", "w", stdout); theN=read (); m=read (); the      for(intI=1; i<=n;i++) {scanf ("%s", ch+1); Insert (1,0);} the build (); the DP (); -      for(intI=0; i<=len;i++) ans= (Ans+f[m][i])%MoD; in      for(intI=1; i<=m;i++) mul= (mul* -)%MoD; theprintf"%d\n", (mul-ans+mod)%MoD); the     return 0; About}

"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.