BZOJ1030 [JSOI2007] Text generator

Source: Internet
Author: User
Tags ord

Handling the previous puzzle:

If you look at the 60-mode string, you know it's an AC automaton.

So it is the bare AC automaton to do DP, and then a look, M <= 100, is really a question of conscience, not without matrix optimization.

Here's a trick: to figure out which states are invalid when you're building an automaton, I forgot to add a word (line 51) and WA two times ...

 

So began to review (re-learn) AC automata ... All kinds of tragedies ... Finally a dropped the

1 Const2Prime:longint =10007;3  4 var5Q, FAI:Array[0..10000] ofLongint;6Tail:Array[0..10000] ofBoolean;7Tr:Array[0..7000,0.. -] ofLongint;8F:Array[0.. the,0..6100] ofLongint;9 I, N, M, tot, Len, J, ans, sum:longint;Ten st:string; One   A procedureMake_trie; - var - p, X, I:longint; the   - begin -P: =1; -    forI: =1  toLen Do begin +x: = Ord (St[i])-Ord ('A') +1; -     ifTr[p, X] =0  Then begin + Inc (TOT); ATr[p, X]: =tot; at     End; -     ifTAIL[P] ThenTail[tr[p, X]]: =true; -P: =tr[p, x]; -   End; -TAIL[P]: =true; - End; in   - procedureMake_acmach; to var + h, T, I, X, X1, y:longint; -   the begin *q[1] :=1; $fai[1] :=0;Panax NotoginsengH: =1; -T: =1; the    whileH <= T Do begin +x: =Q[h]; A Inc (h); the      forI: =1  to  -  Do begin +Y: =tr[x, I]; -       ifY >0  Then begin $ Inc (T); $Q[t]: =y; -X1: =Fai[x]; -          whileTrue Do begin the           ifTR[X1, I] >0  Then begin -Fai[y]: =tr[x1, I];Wuyi             ifTAIL[TR[X1, I]] ThenTail[tr[x, I]]: =true; the  Break -           End; WuX1: =fai[x1]; -         End; About       End; $     End; -   End; - End; -   A procedureDP (t:longint); + var the I, J, X:longint; -   $ begin the    forI: =1  toTot Do begin the     ifTail[i] Thencontinue; the      forJ: =1  to  -  Do begin thex: =i; -        whileTrue Do begin in         ifTr[x, J] >0  Then begin theF[t, Tr[x, j]]: = (f[t, tr[x, J]) + F[t-1, I])MoDPrime; the Break ; About         End; thex: =Fai[x]; the       End; the     End; +   End; - End; the  Bayi begin the readln (n, m); theTot: =1; - Fillchar (tail, sizeof (tail), false); -Fillchar (tr, sizeof (TR),0); the    forI: =1  to  -  Dotr[0, I]: =1; the    forI: =1  toN Do begin the Readln (ST); theLen: =Length (ST); - Make_trie; the   End; the Make_acmach; theSum: =1;94    forI: =1  toM Do theSum: = (SUM * -)MoDPrime; thef[0,1] :=1; the    forI: =1  toM Do98 DP (i); About    forI: =1  toTot Do -     if  notTail[i] ThenAns: = (ans + f[m, I])MoDPrime;101Writeln ((Sum-ans + prime)MoDprime);102 End.
View Code

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.