"POJ2778" DNA Sequence (ac automata)

Source: Internet
Author: User

Test instructions

We learned in biology class thatthere are only A, C, T and G four fragments of DNA sequence.

After scientific discovery, theDNA sequence contains certain fragments that produce bad genes, such as fragment "ATC" is a bad fragment , then "ATCC", "CATCAA", " ATC ATC "are bad DNA sequences, these bad fragments we can call viral fragments ."

Now known as m virus fragments , ask the length of the DNA sequence of n , how many species may not contain viral fragments. The answer may be large, modulo 100000.

"Data size and conventions"

0<=m<=10 virus fragment length not exceeding 10, contains only a,t,c,g letters

1<=n<=2000000000

Train of thought: AC automatic machine

Because Fail[i] must be a prefix of I suffix, fail[i] If the virus I must have a virus

Transfer:

  {      dp[0,1]:=1;    for i:=1 to m do    for eachedge(i,j)    begin     dp[i,j]:=dp[i,j]+dp[i-1,i];    end;              }Optimization with matrix multiplication
1 Constmo=100000;2 typeArr=Array[1.. the,1.. the] ofInt64;3 varY,c,ans,d:arr;4SArray[1..4] ofChar;5MapArray[1..10000,'A'..'Z'] ofLongint;6F,b,q:Array[1..200000] ofLongint;7 M,n,i,j,k,t,sum,num:longint;8 ch:string;9 Ten procedurebuild; One varI,k,d:longint; A begin -k:=1; d:=Length (CH); -   fori:=1  toD Do the  begin -   ifmap[k,ch[i]]=0  Then beginInc. (NUM); Map[k,ch[i]]:=num;End; -k:=Map[k,ch[i]]; -  End; +b[k]:=1; - End; +  A procedureAcauto; at varT,w,i,u,p,son:longint; - begin -t:=0; w:=1; q[1]:=1; -   whileT<w Do -  begin -Inc (T); u:=Q[t]; in    fori:=1  to 4  Do -    ifMap[u,s[i]]>0  Then to    begin +son:=Map[u,s[i]]; -p:=F[u]; the     ifu=1  Thenf[son]:=1 *      Elsef[son]:=Map[p,s[i]]; $Inc (W); q[w]:=Son;Panax Notoginseng    End -     Else the     begin +p:=F[u]; A      ifu=1  Thenmap[u,s[i]]:=1 the       Elsemap[u,s[i]]:=Map[p,s[i]]; +     End; -  End; $ End; $  - begin -Assign (input,'poj2778.in'); Reset (input); theAssign (output,'Poj2778.out'); Rewrite (output); - readln (m,n);Wuyinum:=1; thes[1]:='A'; s[2]:='C'; s[3]:='G'; s[4]:='T'; -   fori:=1  toM Do Wu  begin - READLN (CH); About build; $  End; - Acauto; -   fori:=2  toNum Do -   ifb[f[i]]=1  Thenb[i]:=1; A  +   fori:=1  toNum Do the   ifb[i]=0  Then -     forj:=1  to 4  Do $     ifb[map[i,s[j]]]=0  ThenInc (D[I,MAP[I,S[J]]); the  thet:=N; the   fori:=1  toNum Doans[i,i]:=1; they:=D; -   whileT>0  Do in  begin the   ifT and 1=1  Then the   begin About     fori:=1  toNum Do the      forj:=1  toNum Doc[i,j]:=0; the     fori:=1  toNum Do the      fork:=1  toNum Do +     begin -       forj:=1  toNum Doc[i,k]:=c[i,k]+ans[i,j]*Y[j,k]; theC[I,K]:=C[I,K]MoDmo;Bayi     End; the     fori:=1  toNum Do the      forj:=1  toNum Doans[i,j]:=C[i,j]; -   End; -    fori:=1  toNum Do the     forj:=1  toNum Doc[i,j]:=0; the    fori:=1  toNum Do the     fork:=1  toNum Do the    begin -      forj:=1  toNum Doc[i,k]:=c[i,k]+y[i,j]*Y[j,k]; theC[I,K]:=C[I,K]MoDmo; the    End; the    fori:=1  toNum Do94     forj:=1  toNum Doy[i,j]:=C[i,j]; theT:=t>>1; the  End; the   fori:=1  toNum DoSum:= (sum+ans[1, I])MoDmo;98 writeln (sum); About  - 101 close (input);102 close (output);103 End.

"POJ2778" DNA Sequence (ac automata)

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.