Tag: Name OID indicates CTO stack using HDU push tin
Expect, $DP $.
Set $dp[i]$ indicates the desired number of steps required to reach the target position at the current position $i$.
Because there is a direct jumping scheme, it is necessary to preprocess each position at the end of the last hop in which position $i$ finally jumped to the position of $t[i]$.
Well, $DP [I]=sum (1/6*dp[t[i+j]]) +1$.
#pragmaComment (linker, "/stack:1024000000,1024000000")#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<map>#include<Set>#include<queue>#include<stack>#include<iostream>using namespaceStd;typedefLong LongLL;Const DoublePi=acos (-1.0), eps=1e-6;voidFile () {freopen ("D:\\in.txt","R", stdin); Freopen ("D:\\out.txt","W", stdout);} Template<classT>inlinevoidRead (T &x) { Charc =GetChar (); X=0; while(!isdigit (c)) C =GetChar (); while(IsDigit (c)) {x= x *Ten+ C-'0'; C=GetChar (); }}intn,m;intt[100010];BOOLf[100010];vector<int>tree[100010];Doubledp[100010];voidDfsintXinty) {T[y]=Max (t[y],x); for(intI=0; I<tree[y].size (); i++) DFS (X,tree[y][i]);}intMain () { while(~SCANF ("%d%d",&n,&m)) {if(n==0&&m==0) Break; Memset (F,0,sizeoff); for(intI=0; i<=n;i++) tree[i].clear (); for(intI=0; i<m;i++) { intb; scanf"%d%d",&a,&b); Tree[b].push_back (a); F[a]=1; } for(intI=1; i<=n;i++) t[i]=i; for(intI=0; i<=n;i++) { if(F[i])Continue; DFS (i,i); } memset (DP,0,sizeofDP); for(inti=n-1; i>=0; i--) { for(intj=1; j<=6; j + +) { if(i+j>=n)Continue; Dp[i]=dp[i]+1.0/6*dp[t[i+J]]; } Dp[i]=dp[i]+1; } printf ("%.4f\n", dp[0]); } return 0;}
HDU 4405 Aeroplane Chess