hdu 3853 LOOPS (概率dp 逆推求期望)
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 2630 Accepted Submission(s): 1081
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.
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
0.00 0.50 0.50 0.50 0.00 0.50
0.50 0.50 0.00 1.00 0.00 0.00
题意:有一个迷宫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 逆推求期望)的更多相关文章
- HDU 3853 LOOPS 概率DP入门
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- sgu 495. Kids and Prizes (简单概率dp 正推求期望)
题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...
- 概率dp——逆推期望+循环迭代zoj3329
首先要推出dp[i]的期望方程,会发现每一项都和dp[0]相关, 那我们将dp[i]设为和dp[0]有关的式子dp[i]=a[i]*dp[0]+b[i],然后再回代到原来的期望方程里 然后进行整理,可 ...
- hdu 4336 Card Collector (概率dp+位运算 求期望)
题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- HDU 3853 LOOP (概率DP求期望)
D - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit St ...
- LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)
题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1 ...
- HDU 3853 LOOPS 可能性dp(水
在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
随机推荐
- Angular入门(四) Router 替换当前页面
1.在 xx.html 中直接 写标签 <a [routerLink]="['/home']">home</a> 2.在 xx.html 中 ...
- asp.net mvc 中"未找到路径“/favicon.ico”的控制器或该控制器未实现 IController。"
FavIcon.ico是一个特殊的文件,它是浏览器请求一个网站时出现的.某些浏览器在书签和收藏夹中使用这个图标.在与这些图标相关的网站被打开时,某些浏览器也在标题栏或浏览器标签中中显示这个图标. 当一 ...
- JAVA数据类型(转)
java中数据的基本类型分为: 基本数据类型和引用数据类型,对此不多介绍: 接下来讨论一下java中数据类型存储在哪 基本数据类型存储在哪,取决于基本类型在哪声明: 1 ...
- php总结2——php中的变量、数据类型及转换、运算符、流程控制中的分支结构
2.1 php中的变量: 定义变量:$变量名称=值: 变量名称:$开头 $之后的第一位必须是字母 $第二位之后可以是字母.数字或者是下划线.习惯上变量名称有实际含义,第二个单词后首字母大 ...
- 【题解】[CJOI2019]Cipher
[题解][CJOI2019]Cipher 题目描述 给定你\(p\)进制数\(s\),\(p \le 9+26\),求对于十进制数\(k\),求\(k^s \equiv ? \mod m\) 数据范围 ...
- Java异步编程第2篇
假如如今有一个Buttonbutton,Buttonbutton上有click和doubleclick事件. 两个不同的事件须要进行不同的处理.这时候就须要为对应的事件注冊Listener了.改动后的 ...
- Spring IOC 容器源码分析(转)
原文地址 Spring 最重要的概念是 IOC 和 AOP,本篇文章其实就是要带领大家来分析下 Spring 的 IOC 容器.既然大家平时都要用到 Spring,怎么可以不好好了解 Spring 呢 ...
- 关于JavaScript中prototype机制的理解
最近几天一直在研究JavaScript中原型的机制,从开始的似懂非懂,到今天终于有所领悟.不敢说彻底理解,但是起码算知道怎么回事了. 为什么一开始似懂非懂 开始了解一遍原型机制后,感觉知其然但不知其所 ...
- CUDA: 常量内存与事件
常量内存: 常量内存用于保存在核函数执行期间不会发生变化的数据,在变量面前添加 __constant__ 修饰符: __constant__ Sphere s[SPHERES]; cudaMe ...
- GstAppSrc简介
Description The appsrc element can be used by applications to insert data into a GStreamer pipeline. ...