标签:
Description
Input
Output
Sample Input
2 0 8 3 2 4 4 5 7 8 0 0
Sample Output
1.1667 2.3441
模拟飞行棋
倒着推期望的时候要注意特判能直接飞的点
//做了五题概率dp了终于1A了 开心~
ACcode:
#include <iostream> #include <cstdio> #include <cstring> #define maxn 100010 using namespace std; double dp[maxn]; int from[maxn]; int to[maxn]; int main(){ int n,m; while(scanf("%d%d",&n,&m),n|m){ memset(from,0,sizeof(from)); memset(dp,0,sizeof(dp)); memset(to,0,sizeof(to)); for(int i=0;i<m;++i){ int x,y; scanf("%d%d",&x,&y); to[x]=y; from[y]=x; } for(int i=1;i<=n;++i){ if(to[to[i]])to[i]=to[to[i]]; if(from[from[i]])from[i]=from[from[i]]; } // for(int i=1;i<=n;++i)printf("to[%d] = %d from[%d] = %d\n",i,to[i],i,from[i]); for(int i=n-1;i>=0;--i){ double sum=0; double e=1.0/6; if(to[i]){ dp[i]=dp[to[i]]; continue; } for(int k=1;k<=6;++k) sum+=dp[k+i]*e; dp[i]=sum+1; } printf("%.4lf\n",dp[0]); } return 0; }
标签:
原文地址:http://blog.csdn.net/zp___waj/article/details/51347946