HDU3853 概率DP
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
题意:
最开始他在Map[1][1],出口在Map[n][m];每一次他会消耗两颗神丹,然后每一个格子,有一定概率留在原地,有一定概率向下走一格,有一定概率向右走一格。。。求逃出去的神丹消耗期望。
思路:
dp[i][j]:从(i,j)到(n,m)的期望步数,所求答案即为dp[1][1]。
dp[i][j]=p1*dp[i][j]+p2*dp[i][j+1]+p3*dp[i+1][j](写的时候需要移项dp[i][j])
代码:
#include"bits/stdc++.h" #define db double
#define ll long long
#define vl vector<ll>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = ;
const db PI = acos(-1.0);
const db eps = 1e-;
const ll INF = 0x3fffffffffffffff;
db p1[][];
db p2[][];
db p3[][];
db dp[][];
int n,m;
int main()
{ while(scanf("%d%d",&n,&m)==){
for(int i=;i<=n;i++)
for(int j=;j<=m;j++) cd(p1[i][j]),cd(p2[i][j]),cd(p3[i][j]);
memset(dp,, sizeof(dp));
for(int i=n;i>=;i--){
for(int j=m;j>=;j--){
if(dp[i][j]>eps) continue;
if(p1[i][j]>-eps) continue;
dp[i][j]=(p2[i][j]*dp[i][j+]+p3[i][j]*dp[i+][j]+)/(-p1[i][j]);
}
}
printf("%.3f\n",*dp[][]);
}
return ;
}
HDU3853 概率DP的更多相关文章
- 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 ...
- [hdu3853]LOOPS(概率dp)
题意:迷宫是一个R*C的布局,每个格子中给出停留在原地,往右走一个,往下走一格的概率,起点在(1,1),终点在(R,C),每走一格消耗两点能量,求出最后所需要的能量期望. 解题关键:概率dp反向求期望 ...
- 概率DP入门学习QAQ
emmmm博客很多都烂尾了...但是没空写..先写一下正在学的东西好了 概率DP这东西每次考到都不会..听题解也是一脸懵逼..所以决定学习一下这个东东..毕竟NOIP考过...比什么平衡树实在多了QA ...
- 动态规划之经典数学期望和概率DP
起因:在一场训练赛上.有这么一题没做出来. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6829 题目大意:有三个人,他们分别有\(X,Y,Z\)块钱 ...
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- POJ 2151 Check the difficulty of problems (概率DP)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
- 概率DP light oj 1030
t组数据 n块黄金 到这里就捡起来 出发点1 到n结束 点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6 如果满6个的话 否则 ...
随机推荐
- Design Pattern ->Composite
Layering & Contract Philosophy With additional indirection class CComponent { ; ; ; public: virt ...
- 【起航计划 015】2015 起航计划 Android APIDemo的魔鬼步伐 14 App->Activity->Translucent Blur 模糊背景
这个例子和Translucent不同的一点是Blur,也就是显示在当前Activit背后的其它Activity以模糊方式显示. 这是通过window对象Flag来设置的. // Have the sy ...
- SpringCloud的学习记录(1)
最近一段时间重新学习一边SpringCloud(有半年不用了),这里简单记录一下. 我用的是IntelliJ IDEA开发工具, SpringBoot的版本是2.1.3.RELEASE. 1. 构建M ...
- PhoneGap&jQuery Mobile应用开发环境配置(For Android)
关于移动应用为什么用PhoneGap和jQuery Mobile本文不再赘述,有兴趣的童鞋可以自行问“度娘”,有很多这方面的文章.本文主要介绍PhoneGap&jQuery Mobile移动应 ...
- SSM事务
问题描述:查询用户信息时想级联查出用户订单以及订单详情,在查询用户的时候JDBC是will be managed by Spring,但懒加载用户订单以及订单详情时就will not be manag ...
- NFS笔记(二)NFS服务器配置实例
一.NFS服务器配置实例实验拓扑 二.实验要求及环境 2.1实验环境 NFS服务器 IP:192.168.8.5环境:[root@server7 ~]# uname -aLinux server7.c ...
- 12/13 exercise
gcc -[cog] gcc pro1.o pro2.o //create a executable file x.out if unnamed
- python IDE-pycharm在virtualenv里安装软件
1 windows命令行,进入venv下的scripts目录,执行activate.bat进入虚拟环境 2 以selenium安装为例,输入pip install selenium回车开始安装 3 ...
- Selenium入门16 获取页面源代码
页面源代码:page_source属性 获取源代码之后,再用正则表达式匹配出所有的链接,代码如下: #coding:utf-8 from selenium import webdriver impor ...
- bzoj2568 比特集合
Description 比特集合是一种抽象数据类型(Abstract Data Type) ,其包含一个集合S,并支持如下几种操作: INS M : 将元素 M 插入到集合S中: DEL M : 将集 ...