标签:io sp for bs amp as size nbsp c
有 0到 n 个格子,掷骰子走路,求出到终点的数学期望,有飞行的路线。
dp[i] 存储在i位置走到终点的期望,
转移方程dp[i]=(dp[i+1] ----> dp[i+6])/6+1;
有飞行路线则直接赋值
#include "stdio.h" #include "string.h" double dp[100010]; int hash[100010]; int main() { int n,m,x,y,i,j; while (scanf("%d%d",&n,&m)!=EOF) { if (n+m==0) break; memset(hash,-1,sizeof(hash)); while (m--) { scanf("%d%d",&x,&y); hash[x]=y; } memset(dp,0,sizeof(dp)); for (i=n-1;i>=0;i--) { if (hash[i]!=-1) dp[i]=dp[hash[i]]; else { for (j=1;j<=6;j++) dp[i]+=dp[i+j]; dp[i]=dp[i]/6+1; } } printf("%.4lf\n",dp[0]); } return 0; }
标签:io sp for bs amp as size nbsp c
原文地址:http://blog.csdn.net/u011932355/article/details/41246595