JSOI2007 Text Generator

Source: Internet
Author: User

1030: [JSOI2007] Text generator time limit:1 Sec Memory limit:162 MB
submit:1613 solved:656
[Submit] [Status] 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
B

Sample Output100
HINT

Code:

1 Constp=10007;2 varA:Array[0..6001,0.. -] ofLongint;3Fail,q:Array[0..6001] ofLongint;4F:Array[0..101,0..6001] ofLongint;5 s:string;6FlagArray[0..6001] ofBoolean;7 I,j,n,m,ans1,ans2,tot,h,t:longint;8 procedureInsert;9  varI,j,now:longint;Ten  begin OneREADLN (s); now:=1; A   fori:=1  toLength (s) Do -   begin -J:=ord (S[i])-ord ('A')+1; the   ifa[now,j]=0  Then beginInc (TOT); a[now,j]:=tot;End; -now:=A[now,j]; -   End; -flag[now]:=true; +  End; - procedureAcmatch; +  varI,now,k:longint; A  begin ath:=0; t:=1; q[1]:=1; fail[1]:=0; -   whileH<t Do -   begin -Inc (h); now:=Q[h]; -    fori:=1  to  -  Do -    begin in    ifa[now,i]=0  Thencontinue; -k:=Fail[now]; to     whilea[k,i]=0  Dok:=Fail[k]; +fail[a[now,i]]:=A[k,i]; -    ifFlag[a[k,i]] Thenflag[a[now,i]]:=true; theInc (T); q[t]:=A[now,i]; *    End; $   End;Panax Notoginseng  End; - procedureInit; the  begin +tot:=1; A readln (n,m); the   fori:=1  to  -  Doa[0, i]:=1; +   fori:=1  toN DoInsert; - Acmatch; $  End; $ procedureDP (x:longint); -  varI,j,k:longint; -  begin the   fori:=1  toTot Do -   beginWuyi   if(Flag[i])or(f[x-1, i]=0) Thencontinue; the    forj:=1  to  -  Do -    begin Wuk:=i; -      whilea[k,j]=0  Dok:=Fail[k]; AboutF[x,a[k,j]]:= (f[x,a[k,j]]+f[x-1, I])MoDp; $    End; -   End; -  End; - proceduremain; A  begin +f[0,1]:=1; the   fori:=1  toM DoDP (i); -ans2:=1; ans1:=0; $   fori:=1  toM DoAns2:= (ans2* -)MoDp; the   fori:=1  toTot DoWriteln (F[m,i]); the   fori:=1  toTot Do the   if  not(Flag[i]) ThenAns1:= (Ans1+f[m,i])MoDp; theWriteln ((ans2-ans1+p)MoDp); -  End; in begin theAssign (input,'Input.txt'); Assign (output,'output.txt'); the reset (input); rewrite (output); About Init; the main; the close (input); close (output); the End. +           
View Code

AC Automatic Template!

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.