hdu 3853 LOOPS (概率dp 逆推求期望)
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 2630 Accepted Submission(s): 1081
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
0.00 0.50 0.50 0.50 0.00 0.50
0.50 0.50 0.00 1.00 0.00 0.00
题意:有一个迷宫r行m列,开始点在[1,1]现在要走到[r,c]
对于在点[x,y]可以打开一扇门走到[x+1,y]或者[x,y+1]
消耗2点魔力
问平均消耗多少魔力能走到[r,c]
分析:
和之前的题类似,逆推
d[i][j]表示从i行j列到r行c列的期望,d[i][j] = 1+d[i][j]*p1 + d[i][j+1]*p2 + d[i+1][j]*p3.
移项就是
d[i][j] = (1.0 + d[i][j+1]*p[i][j].b + d[i+1][j]*p[i][j].c)/(1.0-p[i][j].a);
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <algorithm>
#define LL __int64
const int maxn = 1e3 + ;
using namespace std;
double d[maxn][maxn];
struct node
{
double a, b, c;
}p[maxn][maxn]; int main()
{
int r, c, i, j;
while(~scanf("%d%d", &r, &c))
{
for(i = ; i <= r; i++)
for(j = ; j <= c; j++)
scanf("%lf%lf%lf", &p[i][j].a, &p[i][j].b, &p[i][j].c); memset(d, , sizeof(d));
d[r][c] = ;
for(i = r; i >= ; i--)
for(j = c; j >= ; j--)
if(i==r && j==c)
continue;
else if(p[i][j].a - 1.0==) //因为这错了两次,如果这个点一只是在原地的话,逆推是不可达的点,也就是d[i][j]=0.
continue;
else
d[i][j] = (1.0 + d[i][j+]*p[i][j].b + d[i+][j]*p[i][j].c)/(1.0-p[i][j].a);
printf("%.3lf\n", 2.0*d[][]);
}
return ;
}
hdu 3853 LOOPS (概率dp 逆推求期望)的更多相关文章
- HDU 3853 LOOPS 概率DP入门
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- sgu 495. Kids and Prizes (简单概率dp 正推求期望)
题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...
- 概率dp——逆推期望+循环迭代zoj3329
首先要推出dp[i]的期望方程,会发现每一项都和dp[0]相关, 那我们将dp[i]设为和dp[0]有关的式子dp[i]=a[i]*dp[0]+b[i],然后再回代到原来的期望方程里 然后进行整理,可 ...
- hdu 4336 Card Collector (概率dp+位运算 求期望)
题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 3853 LOOP (概率DP求期望)
D - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit St ...
- LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)
题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1 ...
- HDU 3853 LOOPS 可能性dp(水
在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
随机推荐
- vue element-ui 自动获取光标
<el-input ref="customerInput"></el-input> this.$refs.mark.$el.querySelector('i ...
- AWS:5.公有云编程
主要内容 1.AWS接口 2.使用AWS命令行 3.使用python sdk编程 AWS接口 Console:web控制台 登录amazon后在"我的账户" -> AWS管理 ...
- Upgrading Elasticsearch
Upgrading Elasticsearch | Elasticsearch Reference [5.6] | Elastic https://www.elastic.co/guide/en/el ...
- babylon
https://github.com/babel/babel babylon - npm https://www.npmjs.com/package/babylon Babel is a compil ...
- Tomcat学习笔记【2】--- Tomcat安装、环境变量配置、启动和关闭
本文主要讲Tomcat的安装和配置. 一 Tomcat安装 1.1 下载 下载地址:http://tomcat.apache.org/ 1.2 安装 Tomcat是不需要安装的,解压压缩包即可. 在安 ...
- error LNK2022: metadata operation failed (801311D6) : Differing number of methods in duplicated types
本文主要是记录一个C++编译错误的解决方案,具体错误请看本文标题. 这个错误主要是由Managed C++的增量编译导致的,这是VS 2008的一个bug,在VS 2010已经修复,我使用的正式201 ...
- JavaScript 四种显示数据方式
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- POJ - 2299 Ultra-QuickSort 【树状数组+离散化】
题目链接 http://poj.org/problem?id=2299 题意 给出一个序列 求出 这个序列要排成有序序列 至少要经过多少次交换 思路 求逆序对的过程 但是因为数据范围比较大 到 999 ...
- <密码学入门>关于RSA算法的加密解密及代码实现
RSA算法 是一种公钥加密算法,RSA算法相比别的算法思路非常清晰,但是想要破解的难度非常大.RSA算法基于一个非常简单的数论事实:两个素数相乘得到一个大数很容易,但是由一个大数分解为两个素数相乘却非 ...
- C++中输出 位宽和小数点后位数 的控制
要用到这个头文件: <iomanip> setw(x) : 表示控制输出x的位宽 setprecision(x) :表示 控制输出小数点后 x 位 cout.precision(x): 表 ...