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. (转)淘淘商城系列——初始SolrCloud

    http://blog.csdn.net/yerenyuan_pku/article/details/72944611 本文我只是简单介绍一下SolrCloud,如果大家要是感兴趣的话,可以参考Sol ...

  2. What is the difference between Gradle Build and Gradle Sync?

    Gradle Build helps you to compile your Android app into an APK while Gradle Sync will sync up all yo ...

  3. url取值乱码问题,url加中文导致页面不能加载问题 js unicode转码,以及解码

    很多时候写H5或其他适配时,打不开url.很多原因是因为浏览器不支持中文url,从url拿 出来的中文值也会乱码,这时候就必须把中文转化成Unicode值,去进行页面传值 中文转Unicode fun ...

  4. Windows如何正确的修改administrator用户名

    无论是服务器还是电脑.修改默认的administrator的用户总是好的.话不多少.直接上图 1.win+r  输入:gpedit.msc 2.按照我下图的圈圈找到重命名系统管理员账户并自定义 3.重 ...

  5. Vue和JQuery相比,除了节省了开发成本,还有什么优点?

    1.模块化,变量都是私有作用域,JQuery只能用全局变量.闭包,影响性能 2.组件化 3.因为1,所以方便维护 vuex 要注意刷新清空的问题 vue-router是局部刷新,window.loca ...

  6. PAT (Advanced Level) Practice(更新中)

    Source: PAT (Advanced Level) Practice Reference: [1]胡凡,曾磊.算法笔记[M].机械工业出版社.2016.7 Outline: 基础数据结构: 线性 ...

  7. 洛谷——P2814 家谱

    P2814 家谱 题目背景 现代的人对于本家族血统越来越感兴趣. 题目描述 给出充足的父子关系,请你编写程序找到某个人的最早的祖先. 输入输出格式 输入格式: 输入由多行组成,首先是一系列有关父子关系 ...

  8. jQuery练习:表单模态框

    代码:基于事件冒泡原理和事件委托 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta cha ...

  9. 某种密码(password.*)

    关于某种密码有如下描述:某种密码的原文A是由N个数字组成,而密文B是一个长度为N的01数串,原文和密文的关联在于一个钥匙码KEY.若KEY=∑▒[Ai*Bi],则密文就是原文的一组合法密码.现在有原文 ...

  10. springCloud学习-高可用的分布式配置中心(Spring Cloud Config)

    1.简介 高可用的分布式配置中心,即将配置中心做成一个微服务,将其集群化,从而达到高可用.config-server和config-client向eureka-server注册,且将config-se ...