The topic probably said there is a plane has n points, from 1 points to the N point, each step can only go to the sequence number is larger than the current point and the series can not contain a given m sequence of any one, ask 1 to go to the shortest of N.
Using the M sequence to build an AC automaton, the suffix contains the entire sequence of nodes marked, and then use dp[u][s] to indicate that the end of the sequence to go to the U point and the suffix state is the shortest point of the robot S node, so that on the AC automaton running on the transfer is OK.
1#include <cstdio>2#include <cstring>3#include <cmath>4#include <queue>5#include <algorithm>6 using namespacestd;7 #defineMAXN 6668 inttn,ch[maxn][ -],FAIL[MAXN];9 BOOLFLAG[MAXN];Ten voidInsertint*a,intN) { One intx=0; A for(intI=0; i<n; ++i) { - inty=A[i]; - if(ch[x][y]==0) ch[x][y]=++tn; thex=Ch[x][y]; - } -flag[x]=1; - } + intN; - voidGetfail () { +memset (fail,0,sizeof(fail)); Aqueue<int>que; at for(intI=1; i<=n; ++i) { - if(ch[0][i]) Que.push (ch[0][i]); - } - while(!Que.empty ()) { - intx=Que.front (); Que.pop (); - for(intI=1; i<=n; ++i) { in if(Ch[x][i]) { - Que.push (Ch[x][i]); tofail[ch[x][i]]=Ch[fail[x]][i]; +flag[ch[x][i]]|=Flag[ch[fail[x]][i]]; -}Elsech[x][i]=Ch[fail[x]][i]; the } * } $ }Panax Notoginseng Doublex[ -],y[ -],dist[ -][ -],d[ -][MAXN]; - inta[6]; the intMain () { + intm,k; A while(~SCANF ("%d%d", &n,&m) && (n| |L)) { the for(intI=1; i<=n; ++i) { +scanf"%LF%LF", x+i,y+i); - } $tn=0; $memset (CH,0,sizeof(CH)); -memset (Flag,0,sizeof(flag)); - while(m--){ thescanf"%d",&k); - for(intI=0; i<k; ++i) scanf ("%d", A +i);Wuyi Insert (a,k); the } - Getfail (); Wumemset (Dist,0,sizeof(Dist)); - for(intI=1; i<=n; ++i) { About for(intj=i+1; j<=n; ++j) { $Dist[i][j]=sqrt ((X[i]-x[j]) * (X[i]-x[j]) + (Y[i]-y[j]) * (y[i]-y[j])); - } - } - for(intI=1; i<=n; ++i) { A for(intj=0; j<=tn; ++J) d[i][j]=-1; + } thed[0][0]=0; - for(intI=0; i<n; ++i) { $ for(intj=0; j<=tn; ++j) { the if(d[i][j]<0)Continue; the if(i==0&&!flag[ch[0][1]]){ thed[1][ch[0][1]]=0; the Continue; - } in for(intk=i+1; k<=n; ++k) { the if(Flag[ch[j][k]])Continue; the if(d[k][ch[j][k]]<0|| D[K][CH[J][K]]>D[I][J]+DIST[I][K]) d[k][ch[j][k]]=d[i][j]+Dist[i][k]; About } the } the } the Doubleres=-1; + for(intI=0; i<=tn; ++i) { - if(d[n][i]<0)Continue; the if(res<0|| Res>d[n][i]) res=D[n][i];Bayi } the if(res<0) puts ("Can not be reached!"); the Elseprintf"%.2f\n", res); - } - return 0; the}
HDU4511 Xiao Ming Series Story--the test of the girlfriend (AC automaton +DP)