【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 ...
随机推荐
- 高德API+.NET解决租房问题(新增诚信房源)
作者:李国宝链接:https://zhuanlan.zhihu.com/p/22105008(欢迎点赞)来源:知乎著作权归作者所有.商业转载请联系作者获得授权,非商业转载请注明出处. 之前有小伙伴反应 ...
- Java重写构造方法
public class TestSuper { public static void main(String[] args) { new ChildClass("alex", 1 ...
- django生产环境中部署
https://www.cnblogs.com/chenice/p/6921727.html 本节内容 uwsgi 介绍 uwsgi安装使用 nginx安装配置 django with nginx 如 ...
- guacamole实现上传下载
目录 1. 源码解读 2. 上传下载的核心代码 分析的入手点,查看websocket连接的frame 看到首先服务端向客户端发送了filesystem请求,紧接着浏览器向服务端发送了get请求,并且后 ...
- 【C#】 RBAC 权限框架
[C#] RBAC 权限框架 一. 名词解释 1. 用户 : 登录的账号, 和角色挂钩,可拥有多个角色 2. 角色 : 账号所属的角色, 和权限挂钩,可拥有多个权限 3. 权限 : 角色拥有的操作权限 ...
- 【jQuery】 Ajax
[jQuery] Ajax $.ajax({ type: "Post", // 发包方式 cache: false, // 是否缓存 contentType: "appl ...
- java网络编程框架
虽然写过一些网络编程方面的东西,但还没有深入研究过这方面的内容,直接摘录一些文章,后续整理 原文地址:http://blog.csdn.net/lwuit/article/details/730613 ...
- (vue01)vue环境搭建
腾讯,百度,网易....这么大媒体平台咋老推送这么lower的信息? 你们不缺钱啊....我这么善良的孩子都别你们带坏了 强烈鄙视马化腾 强烈鄙视李彦宏 参考地址: https://segmentfa ...
- LeetCode 707 ——设计链表
1. 题目 2. 解答 用一个单链表来实现,只有一个头指针.因为不能建立哨兵结点,因此要特别注意是否在头结点处操作. class MyLinkedList { public: struct ListN ...
- tensorflow学习笔记(1)-基本语法和前向传播
tensorflow学习笔记(1) (1)tf中的图 图中就是一个计算图,一个计算过程. 图中的constant是个常量 计 ...