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

like me, I've been brushing water all day, eating date pills .The problem is asking how many strings with at least one given string and a length of $m$. Then, obviously, this multi-string processing problem is to be AC automata.  After the AC automaton is created, the DP on it is available. Actually feel the direct DP also can do, but actually the problem transforms a better do. Find out all the illegal strings and then use the total quantity minus a bit. So $f_{i,j}$ said in the AC automaton Walk $i$ step to reach the node $j$ the number of programs, transfer time without the end of the word node can be.ac automata are all wrong, I'm taking a date pill.Paste the following code:
#include <iostream> #include <cstdio> #include <cstring> #include <algorithm> #include < Cmath> #define FILE (s) freopen (S ".", "R", stdin), Freopen (S ". Out", "w", stdout) #define MAXN 6010#define MoD 10007using namespace Std;typedef Long long llg;int n,m,fl[maxn],d[maxn],ans;int Ch[maxn][26],sz,f[101][maxn];bool val[ Maxn],w[maxn];int getint () {int w=0;bool q=0;char C=getchar (); while (c> ' 9 ' | | c< ' 0 ') &&c!= '-') C=getchar (), if (c== '-') C=getchar (), Q=1;while (c>= ' 0 ' &&c<= ' 9 ') w=w*10+c-' 0 ', C=getchar (); return q?-w:w;} void gi (int &x) {if (x>=mod) x%=mod;} void Insert () {char c=getchar (); while (c> ' Z ' | | c< ' a ') C=getchar (), int u=0;while (c>= ' a ' && c<= ' Z ') {if (!ch[u][c-' a ']) ch[u][c-' a ']=++sz;u=ch[u][c-' A ']; C=getchar ();} Val[u]=1;}    void getf () {int l=0,r=0,u;d[r++]=0;        while (l!=r) {u=d[l++]; for (int i=0,j;i<26;i++) if (Ch[u][i]) {j=fl[u];while (!ch[j][i] && j) j=fl[j];if (u!=j) {fl[ch[u][i]]=ch[ J][i];val[ch[u][i]]|                =val[ch[j][i]];}            D[r++]=ch[u][i];    } else ch[u][i]=ch[fl[u]][i]; }}int Main () {File ("a"); N=getint (); M=getint (); while (n--) insert (), GETF (); f[0][0]=ans=1;for (int i=0;i<m;i++) for ( int u=0;u<=sz;u++) if (!val[u]) for (int. j=0;j<26;j++) F[i+1][ch[u][j]]+=f[i][u],gi (F[i+1][ch[u][j]]); for (int i= 1;i<=m;i++) Ans*=26,gi (ans), for (int u=0;u<=sz;u++) if (!val[u]) ans-=f[m][u],ans+=mod,gi (ans);p rintf ("%d", ans ); return 0;}

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.