【HDU3853】LOOPS [期望DP]
LOOPS
Time Limit: 5 Sec Memory Limit: 64 MB
[Submit][Status][Discuss]
Description
Akemi Homura is a Mahou Shoujo (Puella Magi/Magical 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.
Input
The first line contains two integers R and C.
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.
Terminal at EOF
Output
A real number at 3 decimal places (round to), representing the expect magic power Homura need to escape from the LOOPS.
Sample Input
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
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
Sample Output
6.00
6.00
HINT
2 <= R, C <= 1000, 答案<=1000000.
Main idea
每个位置有三种情况:不动、向右走一步、向下走一步。给出了每种情况的概率,执行一次情况会产生2的贡献,询问从 (1,1) 到 (n,m)的贡献的期望。多组数据。
Solution
我们运用期望DP求解,我们先令 f[i][j] 表示从(n,m) 到 (i,j) 的期望,然后可以轻易地推出一个式子,左右移项一下即可:

得到了这个式子之后我们就可以从 (n,m) 递推到 (1,1) 了。
Code
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<bitset>
using namespace std;
const int ONE = ; int n,m;
double p[ONE][ONE][],f[ONE][ONE]; int get()
{
int res=,Q=; char c;
while( (c=getchar())< || c>)
if(c=='-')Q=-;
if(Q) res=c-;
while((c=getchar())>= && c<=)
res=res*+c-;
return res*Q;
} int main()
{
while(scanf("%d%d", &n, &m) != EOF)
{
for(int i=;i<=n;i++)
for(int j=;j<=m;j++)
scanf("%lf %lf %lf", &p[i][j][], &p[i][j][], &p[i][j][]); f[n][m] = ;
for(int i=n;i>=;i--)
for(int j=m;j>=;j--)
if(p[i][j][]!= && (i!=n || j!=m))
f[i][j] = (p[i][j][]*f[i][j+] + p[i][j][]*f[i+][j] + ) / (-p[i][j][]); printf("%.3lf\n",f[][]);
}
}
【HDU3853】LOOPS [期望DP]的更多相关文章
- HDU3853 LOOPS 期望DP基础题
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题目大意(只是大意,名字什么的可能和原题描述不一样~): 爱丽丝与华容道 题目描述 爱丽丝是一个 ...
- HDU3853 LOOPS 期望DP 简单
http://acm.hdu.edu.cn/showproblem.php?pid=3853 有一点坑的地方是如果一个地方停在原地的概率为1,那么该地的期望为0,就相当于这个地方也是一个出口... ...
- hdu3853 LOOPS(概率dp) 2016-05-26 17:37 89人阅读 评论(0) 收藏
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- HDU 3853 LOOPS 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...
- [hdu3853]LOOPS(概率dp)
题意:迷宫是一个R*C的布局,每个格子中给出停留在原地,往右走一个,往下走一格的概率,起点在(1,1),终点在(R,C),每走一格消耗两点能量,求出最后所需要的能量期望. 解题关键:概率dp反向求期望 ...
- HDU 3853 LOOPS:期望dp【网格型】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...
- 【期望DP】
[总览] [期望dp] 求解达到某一目标的期望花费:因为最终的花费无从知晓(不可能从$\infty$推起),所以期望dp需要倒序求解. 设$f[i][j]$表示在$(i, j)$这个状态实现目标的期望 ...
- 期望dp专题
一直不明白为什么概率是正推,期望是逆推. 现在题目做多了,慢慢好像有点明白了 poj2096 收集bug, 有n个种类的bug,和s个子系统. 每找到一个bug需要一天. 要我我们求找到n个种类的 ...
- 【BZOJ-1419】Red is good 概率期望DP
1419: Red is good Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 660 Solved: 257[Submit][Status][Di ...
随机推荐
- hdu1505City Game(动态规划)
City Game Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- jmeter+ant的使用
1.安装ant 下载ant,解压到某盘 2.配置环境变量: 变量名称 变量值 备注 ANT_HOME F:\apache-ant-1.10.3 Ant的解压路径 Path %ANT_HOME%\bin ...
- 剑指offer-调整数组顺序使奇数位于偶数前面13
题目描述 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有的奇数位于数组的前半部分,所有的偶数位于数组的后半部分,并保证奇数和奇数,偶数和偶数之间的相对位置不变. class Solu ...
- Faster RCNN代码解析
1.faster_rcnn_end2end训练 1.1训练入口及配置 def train(): cfg.GPU_ID = 0 cfg_file = "../experiments/cfgs/ ...
- 无缘无故出现npm 解析异常的的问题 解决方案
npm cache clean --force try if false delete package.lock.json try again if false npm set registry ht ...
- php解析二维码
第一种方法: 安装PHP扩展 php-zbarcode之前需要先安装ImageMagick.zbar 第二种方法: 不需要那么麻烦,直接使用PHP的第三方类库 下载地址:https://github. ...
- HDU 4582 DFS spanning tree(DFS+贪心)(2013ACM-ICPC杭州赛区全国邀请赛)
Problem Description Consider a Depth-First-Search(DFS) spanning tree T of a undirected connected gra ...
- 软工实践Beta冲刺(3/7)
队名:起床一起肝活队 组长博客:博客链接 作业博客:班级博客本次作业的链接 组员情况 组员1(队长):白晨曦 过去两天完成了哪些任务 描述: 1.界面的修改与完善 展示GitHub当日代码/文档签入记 ...
- Mybatis学习系列(一)入门简介
MyBatis简介 Mybatis是Apache的一个Java开源项目,是一个支持动态Sql语句的持久层框架.Mybatis可以将Sql语句配置在XML文件中,避免将Sql语句硬编码在Java类中.与 ...
- coredump分析
首先通过命令 gdb freeswitch core.60954进入gdb. 这里freeswitch 是产生coredump的可执行应用,core.60954是应用产生的coredump文件. 然后 ...