"bzoj1030" [JSOI2007] Text generator

Source: Internet
Author: User

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.

Solution: Very classical DP problem, we can set the DP "I" "J" for processing to the first bit of the text string to match the J node of the AC Automaton failure scheme number, then the initial state is matched to 0-bit, the initial node in the scheme number, is obviously 1, or the following is 0, and then enumerate the current every possible letter, Put on the automaton run, run to the node, obviously more matching one, will be transferred to him the number of programs can be, but note, if it is a word node or contain the word point so obviously at this time the scheme number to be cleared, with continue implementation, the end state is matched to the last character, each node is possible, So ask for a and. The answer will be reduced by the total number of solutions. Code:
#include <iostream>#include<stdio.h>#include<stdlib.h>#include<algorithm>#include<cstring>#include<queue>using namespacestd;Const intMod=10007;inttr[ the][ -],f[ the];Chara[ -];BOOLb[ the];intn,m,num=0, dp[ -][ the],tot=1, ans=0; voidcl () {memset (b,0,sizeof(b)); memset (TR,0,sizeof(tr)); Memset (F,0,sizeof(f)); Memset (DP,0,sizeof(DP));} voidInsertCharx[]) {    intnow=0, len=strlen (x);  for(intI=0; i<len;i++){        intto=x[i]-'A'; if(!tr[now][to]) tr[now][to]=++num; now=Tr[now][to]; } B[now]=1;} voidBFs () {Queue<int>Q; f[0]=0; Q.push (0);  while(!Q.empty ()) {        intnow=Q.front ();        Q.pop ();  for(intI=0;i< -; i++){            intnumto=tr[now][i],j=F[now]; if(!NUMTO)Continue;  while(J&&!tr[j][i]) j=F[j]; if(TR[J][I]!=NUMTO) f[numto]=Tr[j][i]; if(B[tr[j][i]]) b[numto]=1;        Q.push (NUMTO); }    }} voidDP () {dp[0][0]=1;//     for(intI=1; i<=m;i++){         for(intj=0; j<=num;j++){            if(!dp[i-1][j]| | B[J])Continue;  for(intx=0; x<= -; x + +){                intH=J;  while(H&&!tr[h][x]) h=F[h]; H=Tr[h][x]; DP[I][H]= (dp[i-1][J]+DP[I][H])%MoD; }        }    }}intMain () {cl (); scanf ("%d%d",&n,&m);  for(intI=1; i<=n;i++) {scanf ("%s",&a);    Insert (a);    } BFS ();    DP ();  for(intI=1; i<=m;i++) tot= (tot* -)%MoD;  for(intI=0; i<=num;i++)if(b[i]==0) ans= (Ans+dp[m][i])%MoD; printf ("%d", (tot-ans+mod)%mod);}

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