"Bzoj" "1030" "JSOI2007" text generator

Source: Internet
Author: User

AC Automatic Machine/DP

Orz ZYF

Maya is about to save the election, hurriedly (Xue) XI (xi) the AC automaton ...

In fact, the DP on the AC automaton is not as complex as originally thought ... is to replace the DP transfer relationship with the edge of the AC automaton (but the problem seems to be a trie figure?). )

1 /**************************************************************2 problem:10303 User:tunix4 language:c++5 result:accepted6 time:208 Ms7 memory:7148 KB8 ****************************************************************/9  Ten //Bzoj 1030 One#include <vector> A#include <cstdio> -#include <cstring> -#include <cstdlib> the#include <iostream> -#include <algorithm> - #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) + #defineD (i,j,n) for (int i=j;i>=n;--i) - #definePB Push_back + using namespacestd; AInlineintGetint () { at     intv=0, sign=1;CharCh=GetChar (); -      while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} -      while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -     returnv*Sign ; - } - Const intn=6010, inf=~0u>>2; intypedefLong LongLL; - /******************tamplate*********************/ to Const intMod=10007; + intN,m,cnt=1; - structtrie{ the     intch[ -],cnt,fail; *     BOOLSign ; $ }t[n];Panax NotoginsengInlineintIdCharc) {returnC-'A';} - voidInsChar*s) { the     intx=1, y; + Rep (I,strlen (s)) { Ay=ID (s[i]); the         if(t[x].ch[y]==0) +t[x].ch[y]=++CNT; -x=T[x].ch[y]; $     } $t[x].sign=1; - } - intQ[n]; the voidMake_fail () { -     intL=0, r=-1;Wuyiq[++r]=1; the      while(l<=R) { -         intx=q[l++],y,j; WuRep (I, -){ -j=T[x].fail; About              while(J &&!) T[j].ch[i]) j=T[j].fail; $             if(T[x].ch[i]) { -y=T[x].ch[i]; -T[y].fail=j? T[j].ch[i]:1; -t[y].sign=t[y].sign|t[t[y].fail].sign; Aq[++r]=y; +}ElseT[x].ch[i]=j? T[j].ch[i]:1; the         } -     } $ } the intf[ the][n][2]; the voiddp () { thef[0][1][0]=1; theRep (I,m) F (J,1, CNT) Rep (K, -) F (L,0,1) -         if(t[t[j].ch[k]].sign) in(f[i+1][t[j].ch[k]][1]+=F[I][J][L])%=MOD; the         Else(f[i+1][T[J].CH[K]][L]+=F[I][J][L])%=MOD; the } About CharS[n]; the intMain () { the #ifndef Online_judge theFreopen ("1030.in","R", stdin); +Freopen ("1030.out","W", stdout); - #endif theN=getint (); m=getint ();BayiF (I,1, N) { thescanf"%s", s); the ins (s); -     } - Make_fail (); the DP (); the     intans=0; theF (I,1, CNT) (ans+=f[m][i][1])%=MOD; theprintf"%d\n", ans); -     return 0; the}
View Code 1030: [JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
submit:2224 solved:923
[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 -Hintsource [Submit] [Status] [Discuss]

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