hdu-4405-Aeroplane chess-概率DP

来源:互联网 发布:icp算法源码 编辑:程序博客网 时间:2024/06/02 15:13

还是那么做。。。

无非加了一条跳转。。。几乎都差不多。。

#include <iostream>#include<stdio.h>#include<string.h>#include<math.h>using namespace std;#define maxn 110000#define eps 1e-6#define zero(x) (fabs(x)<0?0:x)double dp[maxn];int pre[maxn];int n;double dos(int x){    if(x>=n)return 0;    if(dp[x]>-0.5)return dp[x];    if(pre[x]!=0)    {        dp[x]=dos(pre[x]);        return dp[x];    }    dp[x]=0;    for(int i=1;i<=6;i++)    {        dp[x]+=(1.0/6)*(dos(x+i)+1);    }    return dp[x];}int main(){    int m,x,y;    while(~scanf("%d%d",&n,&m)&&(n||m))    {        memset(dp,-1,sizeof(dp));        memset(pre,0,sizeof(pre));        for(int i=1;i<=m;i++)        {            scanf("%d%d",&x,&y);            pre[x]=y;        }        printf("%.4f\n",dos(0));    }    return 0;}


0 0
原创粉丝点击