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. 创龙TMS320C6748开发找不到 tl.dsp.evm6748的问题研究

    1. 使用中遇到问题,看了一下帖子说是把tl.dsp.evm6748换成ti.platforms.evm6748可以编译过去.这个包是在XDCtools里面的. js: "D:/ti/ccs ...

  2. Android各版本代号、版本号、API/NDK级别、发布时间

    代号 版本号 API/NDK级别 发布时间 牛轧糖 Nougat 7.1.2 API level 25 2017-2 7.1.1 2016-10 7.0 API level 24 2016-05 棉花 ...

  3. [推荐]spring cloud 详解

    http://blog.csdn.net/column/details/15197.html

  4. KMP板子+Trie板子

    KMP算法是一个字符串匹配算法,最直白的用法就是在一个长度为n的字符串T中查找另一个长度为m字符串P的匹配(总之就是用于文本中进行单个字符串的匹配). 对于这个问题,暴力算法是很好做的,直接对于T的每 ...

  5. 并查集——hdu1232(入门)

    传送门:畅通工程 实质是求连通分支的数量 #include <iostream> #include <cstdio> #include <algorithm> us ...

  6. lintcode-119-编辑距离

    119-编辑距离 给出两个单词word1和word2,计算出将word1 转换为word2的最少操作次数. 你总共三种操作方法: 插入一个字符 删除一个字符 替换一个字符 样例 给出 work1=&q ...

  7. web相关基础知识3

    一 .浮动布局   ★元素浮动之后不占据原来的位置,脱离标准流 ★浮动的盒子在一行上显示 ★行内元素浮动之后转换为行内块元素.(不推荐使用,会脱离标准流,转行内元素最好使用display: inlin ...

  8. incorrect integer value for column 问题解决

    最近在用zend框架,然后装了一个项目,发现注册的时候出现 General error: 1366 Incorrect integer value: '' for column 'user_id' a ...

  9. java解析XML的方法

    1.DOM 实现方法 xml文件 <?xml version="1.0" encoding="utf-8"?> <Accounts> & ...

  10. 【bzoj1878】[SDOI2009]HH的项链 树状数组

    题目描述 HH有一串由各种漂亮的贝壳组成的项链.HH相信不同的贝壳会带来好运,所以每次散步完后,他都会随意取出一段贝壳,思考它们所表达的含义.HH不断地收集新的贝壳,因此, 他的项链变得越来越长.有一 ...