Channel
Test instructions: Flying chess, from 0 to N, put the dice, set to a few steps forward, there will be shortcuts, such as 2 and 5 connected together, then you go to 2 o'clock can jump to 5, the last question jumps to n when the average number of dice
Idea: Dp[i]: Reaching I is, the desired number of points from the end
Code:
#include <iostream>#include<string.h>#include<stdio.h>using namespacestd;Const intn=100005;structnode{intY,next;};BOOLVis[n];node Path[n];intfirst[n],t;DoubleDp[n];voidAddintXinty) {path[t].y=y; Path[t].next=First[x]; FIRST[X]=t++;}intMain () {Doubles; intn,m,v; while(cin>>n>>m) {if(m==0&&n==0) Break; Memset (DP,0,sizeof(DP)); memset (Vis,0,sizeof(VIS)); memset (First,0,sizeof(first)); intx, y; T=1; while(m--) {cin>>x>>y; Add (y,x); } Dp[n]=-1; for(intJ=m; i>=0; i--) { if(!Vis[i]) {Vis[i]=true; S=0; for(intk=1; k<=6; k++) s+=dp[i+K]; S/=6; Dp[i]+ = (s+1); } for(intK=first[i]; K k=Path[k].next) {v=path[k].y; DP[V]=Dp[i]; VIS[V]=true; }} printf ("%.4lf\n", dp[0]); } return 0;}
View Code
"Expected DP" HDU 4405 aeroplane Chess