http://acm.hdu.edu.cn/showproblem.php?pid=4405
1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<iostream> 5 using namespace std; 6 7 const int mx=100000+10; 8 int v[mx]; 9 double dp[mx]; 10 11 int main() 12 { 13 int n,m,x,y,i,j; 14 while (cin>>n>>m) 15 { 16 memset(v,0,sizeof(v)); 17 memset(dp,0,sizeof(dp)); 18 if (!n&&!m) return 0; 19 while (m--) 20 { 21 cin>>x>>y; 22 v[x]=y; 23 } 24 for (i=n-1;i>=0;i--) 25 { 26 if (v[i]) {dp[i]=dp[v[i]];continue;} 27 for (j=i+1;j<=i+6;j++) 28 dp[i]+=(dp[j]+1)/6.0; 29 } 30 printf("%.4lf\n",dp[0]); 31 } 32 }