hdu3853LOOPS(概率与期望dp)
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 6457 Accepted Submission(s):
2592
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.
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
representing the expect magic power Homura need to escape from the
LOOPS.
0.00 0.50 0.50 0.50 0.00 0.50
0.50 0.50 0.00 1.00 0.00 0.00
/*
状态可以定义为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)的更多相关文章
- 【BZOJ-4008】亚瑟王 概率与期望 + DP
4008: [HNOI2015]亚瑟王 Time Limit: 20 Sec Memory Limit: 512 MBSec Special JudgeSubmit: 832 Solved: 5 ...
- 概率和期望dp
概率和期望dp 概率和期望好神啊,完全不会. 网上说概率要顺着推,期望要逆着推,然而我目前做的概率期望题正好都与此相反2333 概率: 关于概率:他非常健康 初中概率题非常恐怖.现在来思考一道题: ...
- 【CodeForces】913 F. Strongly Connected Tournament 概率和期望DP
[题目]F. Strongly Connected Tournament [题意]给定n个点(游戏者),每轮游戏进行下列操作: 1.每对游戏者i和j(i<j)进行一场游戏,有p的概率i赢j(反之 ...
- 概率与期望dp相关
概率与期望dp 概率 某个事件A发生的可能性的大小,称之为事件A的概率,记作P(A). 假设某事的所有可能结果有n种,每种结果都是等概率,事件A涵盖其中的m种,那么P(A)=m/n. 例如投掷一枚骰子 ...
- 【算法学习笔记】概率与期望DP
本文学习自 Sengxian 学长的博客 之前也在CF上写了一些概率DP的题并做过总结 建议阅读完本文再去接着阅读这篇文章:Here 前言 单纯只用到概率的题并不是很多,从现有的 OI/ACM 比赛中 ...
- 概率及期望DP小结
资源分享 26 个比较概率大小的问题 数论小白都能看懂的数学期望讲解 概念 \(PS\):不需要知道太多概念,能拿来用就行了. 定义 样本(\(\omega\)):一次随机试验产生的一个结果. 样本空 ...
- 【BZOJ-3450】Tyvj1952Easy 概率与期望DP
3450: Tyvj1952 Easy Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 468 Solved: 353[Submit][Status] ...
- BZOJ 3566 [SHOI2014]概率充电器 ——期望DP
期望DP. 补集转化,考虑不能被点亮的情况, 然后就是三种情况,自己不能亮,父亲不能点亮它,儿子不能点亮它. 第一次计算比较容易,第二次计算的时候需要出去第一次的影响,因为一条线只能传导一次 #inc ...
- BZOJ 1444 [JSOI2009]有趣的游戏 (AC自动机、概率与期望DP、矩阵乘法)
诶这题洛谷居然没有??? 题目链接: https://www.lydsy.com/JudgeOnline/problem.php?id=1444 题解: 我见到主要有三种做法. 一是矩阵乘法.设\(d ...
随机推荐
- quartz 数据库表含义解释
http://blog.csdn.net/tengdazhang770960436/article/details/51019291 一.表信息解析: 1.1.qrtz_blob_triggers : ...
- Android中Adapter和Bridge模式理解和应用
一 Adapter模式 意图: 将一个类的接口转换成客户希望的另外一个接口. Adapter模式使得原本由于接口不兼容而不能在一起工作的那些类可以在一起工作. 适用性: 使用一个已存在的类,而它的接口 ...
- 如何在mac里面,把xcode代码同步到 tfs 的 git库(新git库)
克隆篇请参考:http://www.cnblogs.com/IWings/p/6744895.html 在mac安装visual studio code https://code.visualstud ...
- python开发 面试题
一.简述列表与元组的区别 答: 元组tuple与列表List相同点 元组tuple与列表List都是序列类型的容器对象,可以存放任何类型的数据.支持切片.迭代等操作. 元组tuple与列表List区别 ...
- ubuntu14.04远程软件VNC的安装、设置方法
ubuntu中VNCX11開機啟動保持靜默狀態方法: 1首先安裝vncx11. 2.設置vnc密碼,會自動保存在/home/test/.vnc/passwd中 3.將密碼複製到/etc中 4.在/et ...
- java基本类型和包装类型的区别以及object的公共方法
Java的类型分为两部分,一个是基本类型(primitive),如int.double等八种基本数据类型: 一.基本数据类型: byte:Java中最小的数据类型,在内存中占8位(bit),即1个字节 ...
- display: table-cell; 自适应布局
#extras {display: table-cell;width: 180px;padding-left: 10px;border-right: 1px dotted #d7ad7b;} tabl ...
- do{}while(0)
有时会在源码中或在写代码时在宏定义中用到do...while(0). 采用这种方式进行宏定义, 主要是为了防止出现以下错误 : do{}while(0) 空的宏定义避免出现warnning. #def ...
- 【数值计算方法】二分法求根的C++简单实现
给定精确度ξ,用二分法求函数f(x)零点近似值的步骤如下: 1 确定区间[a,b],验证f(a)·f(b)<0,给定精确度ξ. 2 求区间(a,b)的中点c. 3 计算f(c). (1) 若f( ...
- DP背包问题小总结
DP的背包问题可谓是最基础的DP了,分为01背包,完全背包,多重背包 01背包 装与不装是一个问题 01背包基本模型,背包的总体积为v,总共有n件物体,每件物品的体积为v[i],价值为w[i],每件物 ...