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的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
随机推荐
- 自己珍藏的数据库SQL基础练习题答案
一,基本表的定义与删除. 题1: 用SQL语句创建如下三张表:学生(Student),课程表(Course),和学生选课表(SC),这三张表的结构如表1-1到表1-3所示. 表1-1 Student表 ...
- 文件查找工具Everything小工具的使用
Everything 小工具的使用: 首先它是一款基于名称实时定位文件和目录的搜索工具,有以下几个优点: 快速文件索引 快速文件搜索 较低资源占用 轻松分享文件索引 实时跟踪文件更新 通过使用ever ...
- iOS 设置字体样式
1.iOS设置字体样式 label.font = [UIFont fontWithName:@"Arial-BoldItalicMT" size:24]; 字体名如下: F ...
- BCH分叉是一次站队博弈
BCH分叉在即,很多人说BCH本次分叉实质是大佬间的斗争,主要是本次BCH分叉主要分为两大派别: 一派以BCH用户量最大的客户端Bitcoin ABC开发组为主,要在11月15日展开硬分叉升级,主要升 ...
- Java AQS详解(转)
原文地址 一.概述 谈到并发,不得不谈ReentrantLock:而谈到ReentrantLock,不得不谈AbstractQueuedSynchronizer(AQS)! 类如其名,抽象的队列式的同 ...
- 微信小程序上传项目到github
Step1:点击使用版本控制 点击开发工具右上角的版本控制按钮 Step2:点击初始化本地仓库: 等待初始化结束 Step3:在github新建仓库 Step4: 配置git用户密码或ssh: Ste ...
- PAT 甲级 1104. Sum of Number Segments (20) 【数学】
题目链接 https://www.patest.cn/contests/pat-a-practise/1104 思路 最容易想到的一个思路就是 遍历一下所有组合 加一遍 但 时间复杂度 太大 会超时 ...
- touchweb手机网站图片加载方法(canvas加载和延迟加载)
一.canvas图片加载 关于canvas加载,我的方法是,将文章中所有用到图片的地方,都用canvas代替,给canvas一个data-src,里面存放img的路径,通过canvas方法渲染图片.因 ...
- POJ2104 K-th Number —— 区间第k小 整体二分
题目链接:https://vjudge.net/problem/POJ-2104 K-th Number Time Limit: 20000MS Memory Limit: 65536K Tota ...
- 单页导航菜单视觉设计HTML模板
单页导航菜单视觉设计HTML模板,视觉,企业,html,单页,单页导航菜单视觉设计HTML模板是一款磨砂背景的大气时尚HTML设计网页模板 http://www.huiyi8.com/moban/