1#include <cstdio>2#include <iostream>3#include <cstring>4#include <queue>5 #defineINF 1023336 #defineRep (i,j,k) for (register int i = j; I <= K; i++)7 #defineLow (I,J,K) for (register int i = j; I <= K; i++)8 #defineMAXN 1059 using namespacestd;Ten OneInlineintRead () { A ints =0, t =1;Charc =GetChar (); - while(!isdigit (c)) {if(c = ='-') T =-1; c =GetChar ();} - while(IsDigit (c)) s = S *Ten+ C- -, C =GetChar (); the returnS *T; - } - - intch[maxn* -][4], f[maxn* -], last[maxn* -], val[maxn* -], N, l; + intdp[2][1024x768][1023], key[ A], value[523]; - Charc[ the]; + A intIdxCharc) {if(c = ='A')return 0;if(c = ='T')return 1;if(c = ='C')return 2;if(c = ='G')return 3; } at - intsz; - voidClear () {sz =0; VAL[SZ] =0; F[SZ] =0, Last[sz] =0; memset (ch[0],0,sizeof(ch[0])); Memset (DP,0,sizeof(DP)); } - voidInsertChar*c,intNow ) { - ints = strlen (c), p =0; -Rep (I,0. So1){ in intt = idx (c[i]);if(!ch[p][t]) {Ch[p][t] = ++sz; memset (Ch[sz],0,sizeof(Ch[sz])); VAL[SZ] =0; F[SZ] =0, Last[sz] =0; } -p =Ch[p][t]; to } +VAL[P] |=Now ; - } the * voidGet_fail () { $queue<int>Q;Panax NotoginsengRep (I,0,3) {intU = ch[0][i];if(U) q.push (u);} - while( !Q.empty ()) { the intR =Q.front (); Q.pop (); +Rep (I,0,3){ A intU = ch[r][i];if(!u) {Ch[r][i] = Ch[f[r]][i];Continue; } Q.push (u); the intv = f[r]; while(v &&!ch[v][i]) v = f[v]; F[u] =Ch[v][i]; +Last[u] = Val[f[u]]? F[u]: Last[f[u]; Val[u] |=Val[last[u]]; - } $ } $ } - -InlineintGetkeyintb) { the intRET =0; -Rep (I,1, N)if(b & Key[i]) ret + =Value[key[i]];Wuyi returnret; the } - Wu intMain () { -key[1] =1; Rep (I,2, One) Key[i] = key[i-1] *2; About while(SCANF ("%d%d", &n,&l) = =2 ) { $ Clear (); -Rep (I,1, n) {scanf ("%s", c); Value[key[i]] =read (); Insert (C,key[i]); } get_fail (); - //Rep (I,0,sz) cout<<i<< "<<val[i]<<" <<f[i]<<endl; cout<<endl; - intnow =0, pre =1; dp[now][0][0] =1; ARep (I,0, L-1){ + swap (now,pre); theRep (J,0, key[n+1]-1) -Rep (K,0, SZ) { $ if(!dp[pre][j][k])Continue;//cout<<i<< "<<j<<" "<<k<<" "<<getkey (j) <<endl; theRep (L,0,3){intto = J | Val[ch[k][l]]; Dp[now][to][ch[k][l]] =1; }//cout<<i+1<< "" <<to<< "<<ch[k][l]<<" "<<getkey (To) <<endl; } theDP[PRE][J][K] =0; the } the } - intAns =-1; inRep (J,0, key[n+1]-1){ the if(Ans >= Getkey (j))Continue; theRep (K,0, SZ) { About if(!dp[now][j][k])Continue; theans = max (Ans,getkey (j)); Break; the } the } + if(Ans >=0) printf ("%d\n", ans); - Elseprintf"No Rabbit after 2012!\n"); the }Bayi return 0; the}
A topic AC automata + pressure DP