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]的更多相关文章

  1. HDU3853 LOOPS 期望DP基础题

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题目大意(只是大意,名字什么的可能和原题描述不一样~): 爱丽丝与华容道 题目描述 爱丽丝是一个 ...

  2. HDU3853 LOOPS 期望DP 简单

    http://acm.hdu.edu.cn/showproblem.php?pid=3853 有一点坑的地方是如果一个地方停在原地的概率为1,那么该地的期望为0,就相当于这个地方也是一个出口...   ...

  3. 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 ...

  4. HDU 3853 LOOPS 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...

  5. [hdu3853]LOOPS(概率dp)

    题意:迷宫是一个R*C的布局,每个格子中给出停留在原地,往右走一个,往下走一格的概率,起点在(1,1),终点在(R,C),每走一格消耗两点能量,求出最后所需要的能量期望. 解题关键:概率dp反向求期望 ...

  6. HDU 3853 LOOPS:期望dp【网格型】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...

  7. 【期望DP】

    [总览] [期望dp] 求解达到某一目标的期望花费:因为最终的花费无从知晓(不可能从$\infty$推起),所以期望dp需要倒序求解. 设$f[i][j]$表示在$(i, j)$这个状态实现目标的期望 ...

  8. 期望dp专题

    一直不明白为什么概率是正推,期望是逆推. 现在题目做多了,慢慢好像有点明白了 poj2096 收集bug,  有n个种类的bug,和s个子系统.  每找到一个bug需要一天. 要我我们求找到n个种类的 ...

  9. 【BZOJ-1419】Red is good 概率期望DP

    1419: Red is good Time Limit: 10 Sec  Memory Limit: 64 MBSubmit: 660  Solved: 257[Submit][Status][Di ...

随机推荐

  1. Hystrix入门指南

    Introduction 1.Where does the name come from? hystrix对应的中文名字是“豪猪”,豪猪周身长满了刺,能保护自己不受天敌的伤害,代表了一种防御机制,这与 ...

  2. GDB抓虫之旅(上篇)

    本文来自网易云社区. 作者:盛国存 前言 问: gdb是什么? 答: 强大的UNIX下命令行调试工具. 问: gdb能干什么? 答: 让你随心所欲的驾驭你的程序:Start.Stop.Examine. ...

  3. jmeter插件下载

    https://jmeter-plugins.org/wiki/Start/ 插件下载好后,将插件lib目录下的jar包放在jmeter安装目录下的lib里,插件ext目录下的jar包放在jmeter ...

  4. SQL的鸡肋:“视图”

        不知道当年SQL定义者们设计视图时是出于什么样的考虑.实际效果是,视图夹在SQL指令和表之间,形成了一个三明治的结构.在这种结构下做检索,SQL指令每次都要通过视图转换,才能作用到表上.如果不 ...

  5. 监控memcache服务

    监控memcache服务是否正常,模拟用户(web客户端)检测. 使用nc命令加上set/get来模拟检测,以及监控响应时间及命中率. #!/bin/bash #################### ...

  6. python 动态函数调用及可变参数传入

    定义类及方法 class ParameterFactory(object): ..... def fullLinkTag(self, fromDate, toDate, status, cate='全 ...

  7. 数据结构与算法之顺序栈C语言实现

    顺序栈是一种特殊的顺序表,主要操作是入栈和出栈.将顺序表加一些特定限制,就成了顺序栈. 注: 1.顺序栈C语言实现: 2.按较简单的方式实现,主要帮助理解,可在此基础上修改,更加完善: 3.提供几个简 ...

  8. .Net 面试总结

    今天去面试了一家公司,做电子商务类的网站的,公司的老板应该比较有能量,可以同时拿下若干项目,技术负责人给提了几个问题: 记不清顺序了 .net 构析函数的作用 泛型的主要作用及应用方面 结构与类的区别 ...

  9. Metrics+ElasticSearch+grafana

    Metrics+ElasticSearch+grafana--性能监控解决方案 https://blog.csdn.net/Shiyaru1314/article/details/76906461 利 ...

  10. 【bzoj1922】[Sdoi2010]大陆争霸 堆优化Dijkstra

    题目描述 一张n个点m条边的图,通过每条边需要一定的时间.有一些限制条件,每个限制条件形如“x保护y”,表示到达y的最短时间不能小于到达x的最短时间(即如果在其之前到达,则需要等待至xd到达).问1到 ...