hdu 3853(数学期望入门)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=3853
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 2512 Accepted Submission(s): 1022
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.
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
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
6.000
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <string>
#include <cstdio>
#include <cmath>
const int N=1100;
const double eps=1e-6;
using namespace std;
double dp[N][N],p[N][N][3]; int main()
{
int r,c;
while(cin>>r>>c)
{
for(int i=1;i<=r;i++)
for(int j=1;j<=c;j++)
scanf("%lf%lf%lf",&p[i][j][0],&p[i][j][1],&p[i][j][2]);
memset(dp,0,sizeof(dp));
for(int i=r;i>=1;i--)
for(int j=c;j>=1;j--)
{
if(i==r&&j==c)continue;
if(fabs(1-p[i][j][0])<eps)continue;
dp[i][j]=(p[i][j][1]*dp[i][j+1]+p[i][j][2]*dp[i+1][j]+2)/(1-p[i][j][0]);
}
printf("%.3lf\n",dp[1][1]);
}
return 0;
}
hdu 3853(数学期望入门)的更多相关文章
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- HDU 3853 LOOPS 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...
- UVA&&POJ离散概率与数学期望入门练习[4]
POJ3869 Headshot 题意:给出左轮手枪的子弹序列,打了一枪没子弹,要使下一枪也没子弹概率最大应该rotate还是shoot 条件概率,|00|/(|00|+|01|)和|0|/n谁大的问 ...
- Aeroplane chess HDU - 4405_数学期望_逆推
Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; ...
- UVa 12230 && HDU 3232 Crossing Rivers (数学期望水题)
题意:你要从A到B去上班,然而这中间有n条河,距离为d.给定这n条河离A的距离p,长度L,和船的移动速度v,求从A到B的时间的数学期望. 并且假设出门前每条船的位置是随机的,如果不是在端点,方向也是不 ...
- HDU 4586 Play the Dice(数学期望)
Play the Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- HDU 4465 Candy (数学期望)
题意:有两个盒子各有n个糖(n<=2*105),每天随机选1个(概率分别为p,1-p),然后吃掉一颗糖.直到有一天打开盒子一看,这个盒子没有糖了.输入n,p,求此时另一个盒子里糖的个数的数学期望 ...
- HDU 4405 飞行棋上的数学期望
突然发现每次出现有关数学期望的题目都不会做,就只能找些虽然水但自己还是做不出的算数学期望的水题练练手了 题目大意: 从起点0点开始到达点n,通过每次掷色子前进,可扔出1,2,3,4,5,6这6种情况, ...
- 动态规划之经典数学期望和概率DP
起因:在一场训练赛上.有这么一题没做出来. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6829 题目大意:有三个人,他们分别有\(X,Y,Z\)块钱 ...
随机推荐
- python+Eclipse+pydev环境搭建1
编辑器: Eclipse + pydev插件 1. Eclipse是写JAVA的IDE, 这样就可以通用了,学习代价小. 学会了Eclipse, 以后写Python或者JAVA 都可以. 2. Ec ...
- c++内联函数解析(inline)
一.基本定义 inline是C++语言中的一个关键字,可以用于程序中定义内联函数,inline的引进使内联函数的定义更加简单.说到内联函数,这里给出比较常见的定义,内联函数是C++中的一种特殊函数,它 ...
- webpack 之 plugin
loader和plugins的区别是:前者处理单个文件,而后者作用于整个打包过程 内置插件:BannerPlugin 可以在打包后的文件上方添加备注信息,如版权说明等 // webpack.confi ...
- Canvas标签
1.Canvas标签: HTML5<canvas>元素用于图形的绘制,通过脚本(通常是javascript)来完成<canvas>标签只是图形容器,必须使用脚本来绘制图形.你可 ...
- nginx 配置虚拟机 支持pathinfo
server { server_name shopx.local *.shopx.local; charset utf-8; root /Users/x/www/php/shopx.local/sho ...
- python 学习总结3
Python蟒蛇绘制 一.实现程序如下 import turtle turtle.setup (650, 350, 200, 200)#turtle的绘图窗体turtle.setup(width, h ...
- source not found
Eclipse 调试 时, 无论在activity中哪一行打断点.调试时,都会跳转到activity源码中.报错 source not found : 解决办法: ->在调试的线程上 右键单击 ...
- 【HIHOCODER 1526】 序列的值(二进制DP)
时间限制:20000ms 单点时限:1000ms 内存限制:256MB 描述 给定一个长度为 n 的序列 a[1..n],定义函数 f(b[1..m]) 的值为在 [0,m-1] 内满足如下条件的 i ...
- Oracle の ty_str_split + MySQL の proc_split
oracle实现字符串分割 功能描述:用指定分隔符切割输入的字符串,返回一维数组,每个数组元素为一个子串. ); CREATE OR REPLACE FUNCTION fn_split (p_str ...
- MySQL 慢查询优化
为什么查询速度会慢 1.慢是指一个查询的响应时间长.一个查询的过程: 客户端发送一条查询给服务器 服务器端先检查查询缓存,如果命中了缓存,则立可返回存储在缓存中的结果.否则进入下一个阶段 服务器端进行 ...