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 ...
随机推荐
- C# Task多线程
来自Eleven老师示例 private void btnTask_Click(object sender, EventArgs e) { Console.WriteLine(); Console.W ...
- CAD调用导角命令,并返回导角的圆弧对象
主要用到函数说明: _DMxDrawX::SendStringToExecuteFun 把命令当着函数执行,可以传参数,详细说明如下: 参数 说明 IDispatch* pParam 命令参数,IMx ...
- vue命令行创建运行工程
// install vue-cli 安装依赖包 npm install --g vue-cli// 使用vue-cli初始化项目 vue init webpack my-project// inst ...
- 【JAVA】简陋的学生信息管理系统
因为之前写了一个学生信息管理系统,但还是处于命令行界面,不美观,于是打算做一个完整的界面出来. 在网上查阅资料后发现C++本身是不支持图形化界面的(可以使用第三方的Qt来做) 权衡之下还是选择了JAV ...
- CF51F Caterpillar (边双+树形DP)
题目传送门 题目大意:给你一张n个点m条边的图.每次操作可以把两个点合并成一个(与之相连的边也都要连到新点上).求把图中每个联通块都变成“毛毛虫”的最小操作次数.“毛毛虫”必须是一棵树(可以存在自环) ...
- Linux之FTP/TFTP(vsftp、vsftpd) HTTP(httpd、apache) DHCP(dhcpd)
FTP/TFTP(vsftp.vsftpd): FTP是File Transfer Protocol(文件传输协议)而中文简称为"文传协议".用于Internet上的控制文件的双向 ...
- win10如何进入安全模式的几种方法
首先,说一下安全模式的作用: 安全模式, 用途有很多,常见的作用有以下几点 1. 电脑可能由于安装了某些驱动或者软件,不兼容导致电脑启动不了,可以进入安全模式卸载 2. 电脑中病毒之后,可以进入安全模 ...
- ganglia问题小结
1.gmetad和rrdtool的关系 gmetad负责将轮询gmond拉取到的数据存入rrdtool的文件中,rrdtool 2.gemtad.conf ①命令:/usr/sbin/gmetad - ...
- CDOJ 888 Absurdistan Roads
Absurdistan Roads Time Limit: 5678/3456MS (Java/Others) Memory Limit: 65432/65432KB (Java/Others ...
- 洛谷 P1843 奶牛晒衣服
题目背景 熊大妈决定给每个牛宝宝都穿上可爱的婴儿装 . 于是 , 为牛宝宝洗晒衣服就成了很不爽的事情. 题目描述 熊大妈请你帮助完成这个重任 . 洗完衣服后 , 你就要弄干衣服 . 衣服在自然条件下用 ...