LOOPS

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 6457    Accepted Submission(s):
2592

Problem Description
Akemi Homura is a Mahou Shoujo (Puella Magi/Magical
Girl).

Homura wants to help her friend Madoka save the world. But because
of the plot of the Boss Incubator, she is trapped in a labyrinth called
LOOPS.

The planform of the LOOPS is a
rectangle of R*C grids. There is a portal in each grid except the exit grid. It
costs Homura 2 magic power to use a portal once. The portal in a grid G(r, c)
will send Homura to the grid below G (grid(r+1, c)), the grid on the right of G
(grid(r, c+1)), or even G itself at respective probability (How evil the Boss
Incubator is)!
At the beginning Homura is in the top left corner of the LOOPS
((1, 1)), and the exit of the labyrinth is in the bottom right corner ((R, C)).
Given the probability of transmissions of each portal, your task is help poor
Homura calculate the EXPECT magic power she need to escape from the
LOOPS.

 
Input
The first line contains two integers R and C (2 <=
R, C <= 1000).

The following R lines, each contains C*3 real numbers,
at 2 decimal places. Every three numbers make a group. The first, second and
third number of the cth group of line r represent the probability of
transportation to grid (r, c), grid (r, c+1), grid (r+1, c) of the portal in
grid (r, c) respectively. Two groups of numbers are separated by 4
spaces.

It is ensured that the sum of three numbers in each group is 1,
and the second numbers of the rightmost groups are 0 (as there are no grids on
the right of them) while the third numbers of the downmost groups are 0 (as
there are no grids below them).

You may ignore the last three numbers of
the input data. They are printed just for looking neat.

The answer is
ensured no greater than 1000000.

Terminal at EOF

 
Output
A real number at 3 decimal places (round to),
representing the expect magic power Homura need to escape from the
LOOPS.

 
Sample Input
2 2
0.00 0.50 0.50 0.50 0.00 0.50
0.50 0.50 0.00 1.00 0.00 0.00
 
Sample Output
6.000
 
Source
 
Recommend
chenyongfu   |   We have carefully selected several
similar problems for you:  3857 3854 3849 3850 3851 
 
/*
状态可以定义为dp[i][j],代表从(i,j)到(r,c)所花费魔法值的期望。
然后我们需要考虑这样的状态之间能否正确的转化,利用数学期望的定义以及其线性性
不难写出如下转移方程:dp[i][j] = p[i][j][1]*dp[i][j] + p[i][j][2]*dp[i][j+1] + p[i][j][3]*dp[i+1][j] + 2
(其中p[i][j][k]代表在点(i,j)选择第k种走法的概率)
再化简一下:dp[i][j] = (p[i][j][2]*dp[i][j+1] + p[i][j][3]*dp[i+1][j] + 2)/(1-p[i][j][1])。
最后,需要确定边界,
很明显,dp[r][c]=0,因为当在点(r,c)时,他不需要花费魔法值就可以到达(r,c)
dp[1][1]为答案
*/
#include<iostream>
#include<cstdio>
#include<cstring> #define N 1005 using namespace std;
double dp[N][N],p[N][N][]; int main()
{
int r,c;
while(~scanf("%d%d",&r,&c))
{
for(int i=;i<=r;i++)
for(int j=;j<=c;j++)
for(int k=;k<=;k++)
scanf("%lf",&p[i][j][k]);
dp[r][c]=;
for(int i=r;i>;i--)
{
for(int j=c;j>;j--)
{
if(p[i][j][]==|| (i==r)&&j==c) continue;
dp[i][j]=(p[i][j][]*dp[i][j+]+p[i][j][]*dp[i+][j]+)/(-p[i][j][]);
}
}
printf("%.3lf\n",dp[][]);
}
return ;
}

hdu3853LOOPS(概率与期望dp)的更多相关文章

  1. 【BZOJ-4008】亚瑟王 概率与期望 + DP

    4008: [HNOI2015]亚瑟王 Time Limit: 20 Sec  Memory Limit: 512 MBSec  Special JudgeSubmit: 832  Solved: 5 ...

  2. 概率和期望dp

    概率和期望dp 概率和期望好神啊,完全不会. 网上说概率要顺着推,期望要逆着推,然而我目前做的概率期望题正好都与此相反2333   概率: 关于概率:他非常健康 初中概率题非常恐怖.现在来思考一道题: ...

  3. 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP

    [题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...

  4. 概率与期望dp相关

    概率与期望dp 概率 某个事件A发生的可能性的大小,称之为事件A的概率,记作P(A). 假设某事的所有可能结果有n种,每种结果都是等概率,事件A涵盖其中的m种,那么P(A)=m/n. 例如投掷一枚骰子 ...

  5. 【算法学习笔记】概率与期望DP

    本文学习自 Sengxian 学长的博客 之前也在CF上写了一些概率DP的题并做过总结 建议阅读完本文再去接着阅读这篇文章:Here 前言 单纯只用到概率的题并不是很多,从现有的 OI/ACM 比赛中 ...

  6. 概率及期望DP小结

    资源分享 26 个比较概率大小的问题 数论小白都能看懂的数学期望讲解 概念 \(PS\):不需要知道太多概念,能拿来用就行了. 定义 样本(\(\omega\)):一次随机试验产生的一个结果. 样本空 ...

  7. 【BZOJ-3450】Tyvj1952Easy 概率与期望DP

    3450: Tyvj1952 Easy Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 468  Solved: 353[Submit][Status] ...

  8. BZOJ 3566 [SHOI2014]概率充电器 ——期望DP

    期望DP. 补集转化,考虑不能被点亮的情况, 然后就是三种情况,自己不能亮,父亲不能点亮它,儿子不能点亮它. 第一次计算比较容易,第二次计算的时候需要出去第一次的影响,因为一条线只能传导一次 #inc ...

  9. BZOJ 1444 [JSOI2009]有趣的游戏 (AC自动机、概率与期望DP、矩阵乘法)

    诶这题洛谷居然没有??? 题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1444 题解: 我见到主要有三种做法. 一是矩阵乘法.设\(d ...

随机推荐

  1. Sping装配之——自动装配

    Sping从两个角度来实现自动化装配: 组件扫描(component scaning):spring会自动发现应用上下文中所创建的bean; 自动装配(autowiring):spring自动满足be ...

  2. xadmin站点管理类

    9. Xadmin xadmin是Django的第三方扩展,比使用Django的admin站点更强大也更方便. 文档:https://xadmin.readthedocs.io/en/latest/i ...

  3. css3 animation 中的 steps

    steps Specifies a stepping function, described above, taking two parameters. The first parameter spe ...

  4. Appium 教您完美win10安装Appium1.7.2支持win客户端自动化

    参考内容: https://testerhome.com/topics/10193https://testerhome.com/topics/8223https://testerhome.com/to ...

  5. Oracle开发常用函数 max 最大数 自动加 1 的模式

    create sequence bs_com_seq increment by 1 start with 1 minvalue 1 maxvalue 999999 cycle nocache orde ...

  6. STM32串口IAP实验笔记

    STM32的IAP功能确实方便,以前对此如何实现有所了解,但是一直没去测试,这两天来练了下,可谓困难重重,搞了两天问题也一一解决,下面做些简要的笔记 IAP就是在线应用编程,方便程序升级,可以不用打开 ...

  7. POJ - 3538 - Domestic Networks

    先上题目: Domestic Networks Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 732   Accepted: ...

  8. Configuration must specify a spooling directory

    启动spooling源时报错: 原因:spooling配置文件有误 a1.sources.r1.type = spooldir a1.sources.r1.spooldir = /usr/local/ ...

  9. thymeleaf模板使用th:onclick进行传参

    错误的写法: th:onclick="'javascript:editUser('+${prod.id}+');'" 正确的写法: th:onclick="'javasc ...

  10. hibernate分表保存日志

    @Service("accessLogService")@Transactionalpublic class LogMessageServiceImpl extends BaseD ...