题目链接

LOOPS

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 2630    Accepted Submission(s): 1081

Problem 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 (2 <= R, C <= 1000).

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

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
 
Sample Output
6.000
题意:

题意:有一个迷宫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 逆推求期望)的更多相关文章

  1. HDU 3853 LOOPS 概率DP入门

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total Sub ...

  2. hdu 3853 LOOPS 概率DP

    简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  3. sgu 495. Kids and Prizes (简单概率dp 正推求期望)

    题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...

  4. 概率dp——逆推期望+循环迭代zoj3329

    首先要推出dp[i]的期望方程,会发现每一项都和dp[0]相关, 那我们将dp[i]设为和dp[0]有关的式子dp[i]=a[i]*dp[0]+b[i],然后再回代到原来的期望方程里 然后进行整理,可 ...

  5. hdu 4336 Card Collector (概率dp+位运算 求期望)

    题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  6. HDU 3853 LOOP (概率DP求期望)

    D - LOOPS Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit St ...

  7. LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)

    题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1 ...

  8. HDU 3853 LOOPS 可能性dp(水

    在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...

  9. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

随机推荐

  1. 远程访问(post 传参数) 以及IOUtils复制文件

    package com.action; import java.io.File; import java.io.FileOutputStream; import java.io.InputStream ...

  2. mybatis 运算符转义收录

    在ibatis配置文件写SQL语句的时候对于一些比如“<”,">","<>","&"," ' &q ...

  3. Java使用到的常用类总结

    基本类型 常用:int.long.double.boolean. 不常用:byte.float.char.short

  4. 【题解】 P5021赛道修建

    [题解]P5021 赛道修建 二分加贪心,轻松拿省一(我没有QAQ) 题干有提示: 输出格式: 输出共一行,包含一个整数,表示长度最小的赛道长度的最大值. 注意到没,最小的最大值,还要多明显? 那么我 ...

  5. (转)ARCGIS中坐标转换及地理坐标、投影坐标的定义

    原文地址:http://blog.sina.com.cn/s/blog_663d9a1f01017cyz.html 1.动态投影(ArcMap) 所谓动态投影指,ArcMap中的Data 的空间参考或 ...

  6. ls bash: cannot create temp file for here-document: No space left on device

    出现这种问题,一般是磁盘空间满了,或者是inode满了 使用命令: df -h查询磁盘空间 df -i 查询inode占用 Filesystem Inodes IUsed IFree IUse% Mo ...

  7. java与js互调 调用系统播放器

    <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android=&q ...

  8. iOS本地数据存取,看这里就够了

    本文授权转载,作者:hosea_zhou(简书) 应用沙盒 1)每个iOS应用都有自己的应用沙盒(应用沙盒就是文件系统目录),与其他文件系统隔离.应用必须待在自己的沙盒里,其他应用不能访问该沙盒 2) ...

  9. Express的基本使用

    前言 列表项目Express是一个简介而灵活的node.js Web应用框架提供的一系列强大特性帮助你创建各种 Web 应用,和丰富的HTTP工具. 正文 一个简单的express框架实例 ``` / ...

  10. cmd 环境变量设置方法详细解释

    cmd设置环境变量可以方便我们bat脚本的运行,但是要注意的是变量只在当前的cmd窗口有作用(局部生效),如果想要设置持久的环境变量需要我们通过两种手段进行设置:一种是直接修改注册表,另一种是通过我的 ...