http://acm.hdu.edu.cn/showproblem.php?pid=4405
Obviously, there is no need to consider the dice when the plane, must be better by plane
Set E[i] for the number of steps that are required to walk at the point of I, J is one of the possible points to be cast, if deduced from I to i-j, we are not able to determine the transfer direction of I, because there may be two i-j with a plane whose destination is I, so we choose to derive the desired from I to i+j
If you set g[i] to the number of steps you have already traversed as a fraction of I, be sure that g[i+j] needs to know P (I|I+J), which is the probability of moving from I to the i+j, which is more troublesome
From test instructions, set Match[i] as the destination of the aircraft I, when Match[i] exists, e[i]=e[match[i]], otherwise e[i]=sigma ((e[i+j]+1) * (1/6)), J in range (6)
#include <cstdio> #include <cstring> #include <algorithm>using namespace std;const int maxn=1e5+5; Double E[maxn];int match[maxn];int n,m;void init () { memset (e,0,sizeof (e)); memset (match,0,sizeof (Match)); for (int i=0;i<m;i++) { int f,t; scanf ("%d%d", &f,&t); match[f]=t;} } int lt (int a) {return min (a,n);} void Calc () {for (int i=n-1; i>=0; i--) { if (match[i]!=0) e[i]=e[lt (Match[i])]; else {for (int j=1; j<=6; j + +) { e[i]+= (e[lt (i+j)]+1)/6; } }}} int main () { for (int ti=1; scanf ("%d%d", &n,&m) ==2&& (n| | m); ti++) { init (); Calc (); printf ("%.4f\n", E[0]); } return 0;}
HDU 4405 Aeroplane Chess probability DP Difficulty: 0