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\)块钱 ...
随机推荐
- java文件上传,自动判断文件类型
public enum FileType { /** * JEPG. */ JPEG("FFD8FF"), /** * PNG. */ PNG("89504E47&quo ...
- LayuI固定块关闭
1.近期项目使用了layui的固定块,但是当到某个独立页面时,固定块还在,就显得突兀: 2.通过F12查看,发现代码: <ul class="layui-fixbar" st ...
- poj2065 SETI
题目描述: 多组数据,每次给出一个模数$p$和一个表示答案的字符串, 相当于给出一个方程组:$$a_1*1^{1}+a_2*1^{2}+……+a_n*1^{n}=f_1$$ $$a_1*2^{1}+a ...
- 怎么给xshell服务配置密钥远程登陆
xshell密钥登陆 1.找一台测试服务器xiuxiu-test生成密钥对2. cd ./.ssh/ && 把公钥放在~/.ssh/authorized_keys文件中 cat id ...
- 利用RestTemplate进行http调用
在对接API的时候,会涉及调用第三方的服务,这时候可以利用RestTemplate进行调用,下面给大家展示一个简单的调用demo. package com.tanlu.user.api.control ...
- (16) Cloudflare pki公钥基础设施
该工具组共有8个工具 1.cfssl 常用的可用指令: sign signs a certificate bundle build a certificate bundle genkey genera ...
- virsh 命令
virsh是用与管理虚拟化环境中的客户机和Hypervisor的命令行工具,与virt-manager等工具类似,也是调用libvirt API来实现虚拟化的管理. 在使用virsh命令行进行虚拟化管 ...
- python:端口扫描邮件推送
#!/usr/bin/env python import pickle import smtplib from email.mime.text import MIMEText import nmap ...
- 用springmvc的@RequestBody和@ResponseBody 接收和响应json格式数据
1.controller @Controller @RequestMapping("/rest/v1") public class WelcomeController { @Req ...
- NOI模拟赛(3.13)Hike (远行)
Description Mirada生活的城市中有N个小镇,一开始小镇之间没有任何道路连接.随着经济发展,小镇之间陆续建起了一些双向的道路,但是由于经济不太发达,在建设过程中,会保证对于任意两个小镇, ...