BZOJ1030:[JSOI2007] Text Generator--The puzzle

Source: Internet
Author: User

http://www.lydsy.com/JudgeOnline/problem.php?id=1030

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 -

————————————————————————————

See the string to think of the AC automaton.

It is difficult to read and understand, and the number that must be read and understood.

When you see this, you know it's a DP.

Then we can f[i][j] said (on the AC automaton) walked the J-step to the first node, must read the number of not understand.

So obviously if I's son S is not the end of the string we can read (the node that the fail pointer points to), then F[s][j+1]+=f[i][j].

Then on all the AC automata node ans+=f[i][m] Get a certain number of articles can not read.

One more cut.

#include <cstdio>#include<iostream>#include<cmath>#include<cstring>#include<algorithm>#include<queue>using namespaceStd;typedefLong Longll;Const intp=10007;Const intn=60005;structtrie{BOOLEd; inta[ -]; intfail;} Tree[n];intCnt=0, n,m,f[n][ the];inlinevoidInsertstrings) {    intnow=0; intlen=s.length ();  for(intI=0; i<len;i++){        intt=s[i]-'A'; if(tree[now].a[t]==0) {CNT++; Tree[now].a[t]=CNT; } Now=Tree[now].a[t]; } Tree[now].ed=1; return;}voidGetfail () {Queue<int>Q; tree[0].fail=0;  for(intI=0;i< -; i++){        if(tree[0].a[i]) {tree[tree[0].a[i]].fail=0; Q.push (tree[0].a[i]); }    }     while(!Q.empty ()) {        intu=Q.front (); intp=Tree[u].fail;        Q.pop ();  for(intI=0;i< -; i++){            if(Tree[u].a[i]) {Tree[tree[u].a[i]].fail=Tree[p].a[i];            Q.push (Tree[u].a[i]); }Else{Tree[u].a[i]=Tree[p].a[i]; }        }    if(Tree[p].ed) tree[u].ed=1; }    return;}intMain () {scanf ("%d%d",&n,&m); intans=1;  for(intI=1; i<=m;i++) ans=ans* -%p;  for(intI=1; i<=n;i++){    strings; CIN>>s;    Insert (s);    } getfail (); f[0][0]=1;  for(intj=1; j<=m;j++){     for(intI=0; i<=cnt;i++){        if(!f[i][j-1])Continue;  for(intk=0;k< -; k++){        intv=Tree[i].a[k]; if(Tree[v].ed)Continue; F[V][J]+=f[i][j-1]; F[V][J]%=p; }    }    }     for(intI=0; i<=cnt;i++) {ans-=F[i][m]; Ans= (ans%p+p)%p; } printf ("%d\n", ans); return 0;}

BZOJ1030:[JSOI2007] Text Generator--The puzzle

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.