题目大意:在nxm的方格中,从(1,1)走到(n,m)。每次只能在原地不动、向右走一格、向下走一格,概率分别为p1(i,j),p2(i,j),p3(i,j)。求行走次数的期望。

题目分析:状态转移方程很容易得到:

E(i,j)=p1(i,j)*E(i,j)+p2(i,j)*E(i,j+1)+p3(i,j)*E(i+1,j)。

代码如下:

# include<iostream>
# include<cstdio>
# include<cmath>
# include<cstring>
# include<algorithm>
using namespace std; const double eps=1e-8; int n,m;
double p1[1005][1005];
double p2[1005][1005];
double p3[1005][1005];
double dp[1005][1005]; int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<n;++i)
for(int j=0;j<m;++j)
scanf("%lf%lf%lf",&p1[i][j],&p2[i][j],&p3[i][j]);
dp[n-1][m-1]=0;
for(int i=n-2;i>=0;--i){
if(fabs(1-p1[i][m-1])<eps) continue;
dp[i][m-1]=(p3[i][m-1]*(dp[i+1][m-1]+2)+2*p1[i][m-1])/(1-p1[i][m-1]);
}
for(int i=m-2;i>=0;--i){
if(fabs(1-p1[n-1][i])<eps) continue;
dp[n-1][i]=(p2[n-1][i]*(dp[n-1][i+1]+2)+2*p1[n-1][i])/(1-p1[n-1][i]);
}
for(int i=n-2;i>=0;--i)
for(int j=m-2;j>=0;--j){
if(fabs(1-p1[i][j])<eps) continue;
dp[i][j]=(p2[i][j]*(dp[i][j+1]+2)+p3[i][j]*(dp[i+1][j]+2)+2*p1[i][j])/(1-p1[i][j]);
}
printf("%.3lf\n",dp[0][0]);
}
return 0;
}

  

HDU-3853 LOOPS(概率DP求期望)的更多相关文章

  1. HDU 3853 LOOP (概率DP求期望)

    D - LOOPS Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit St ...

  2. HDU 3853 LOOPS 概率DP入门

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total Sub ...

  3. hdu 3853 LOOPS 概率DP

    简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  4. hdu 3853 LOOPS (概率dp 逆推求期望)

    题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Tota ...

  5. HDU3853-LOOPS(概率DP求期望)

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Su ...

  6. POJ2096 Collecting Bugs(概率DP,求期望)

    Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...

  7. LightOJ 1030 【概率DP求期望】

    借鉴自:https://www.cnblogs.com/keyboarder-zsq/p/6216762.html 题意:n个格子,每个格子有一个值.从1开始,每次扔6个面的骰子,扔出几点就往前几步, ...

  8. HDU 5245 Joyful(概率题求期望)

    D - Joyful Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit S ...

  9. HDU 4405 Aeroplane chess (概率DP求期望)

    题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...

随机推荐

  1. static关键字的理解

    #include<stdio.h> int counter(int i){ static int count=0;//编译时只运行一次 count=count+i; return coun ...

  2. 升级或安装 GNOME Shell

    1.安装经典Gnome桌面系统 install gnome-session-fallbackinstall gnome-appletsinstall indicator-applet indicato ...

  3. [转][C/C++]函数名字修饰(Decorated Name)方式

    1.C/C++函数修饰名: 对于我们的C/C++源程序而言,函数名只是函数的一小部分,函数还有调用方式(参数入栈方式).返回值类型.参数个数和各参数类型等信息,对于C++类成员函数,还有更多信息.这些 ...

  4. C# Sandboxer

    public static string IsolateCallV1(PageContentHandler pHandler) { string name = Guid.NewGuid().ToStr ...

  5. 禁用gridview默认点击效果

    cf_gridview.setSelector(new ColorDrawable(Color.TRANSPARENT)); 然后自己给做一个按下的效果xml文件

  6. libimobiledevice安装步骤

    https://github.com/libimobiledevice/libimobiledevice libimobiledevice安装指南,你还不知道libimobiledevice为何物,赶 ...

  7. linux常用命令:2权限管理命令

    权限管理命令 1.权限管理命令:chmod 命令名:chmod 命令英文原意:change the permissions mode of a file 命令所在路径:/bin/chmod 执行权限: ...

  8. Date and Time

    The PHP date() function is used to format date and/or a time and formats as timestamp to a more read ...

  9. Spring反射机制

    Spring是分层的Java SE/EE应用一站式的轻量级开源框架,以IoC(Inverse of Control)和AOP(Aspect Oriented Programming)为内核,提供了展现 ...

  10. 5、C#基础整理(for 语句经典习题--与 if 的嵌套)

    1.for循环最基本运用:小球每次落地后再弹起是以前的4/5,求第5次弹起后的高度 ; i < ; i++) { high = high*/; } Console.WriteLine(" ...