HDU-3853-期望/dp/坑
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 7826 Accepted Submission(s): 3156
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
#include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<time.h>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define debug puts("debug")
#define LL long long
#define pii pair<int,int>
#define eps 1e-10 double f[][];
double p[][][];
int main()
{
int n,m,i,j,k,t;
while(scanf("%d%d",&n,&m)==){
memset(f,,sizeof(f));
for(i=;i<=n;++i){
for(j=;j<=m;++j){
for(k=;k<;++k)
scanf("%lf",&p[i][j][k]);
}
}
f[n][m]=;
for(i=n;i>=;--i){
for(j=m;j>=;--j){
if(i==n&&j==m) continue;
double p1=p[i][j][],
p2=p[i][j][],
p3=p[i][j][];
if(fabs(p1-)<=eps) {
f[i][j]=;
continue;
}
f[i][j]=(p2*f[i][j+]+p3*f[i+][j]+)/((double)-p1);
}
}
printf("%.3f\n",f[][]);
}
return ;
}
HDU-3853-期望/dp/坑的更多相关文章
- HDU 3853(期望DP)
题意: 在一个r*c的网格中行走,在每个点分别有概率向右.向下或停止不动.每一步需要的时间为2,问从左上角走到右下角的期望时间. SOL: 非常水一个DP...(先贴个代码挖个坑 code: /*== ...
- HDU 3853 期望概率DP
期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] , 右移:[x][y ...
- poj 2096 , zoj 3329 , hdu 4035 —— 期望DP
题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...
- HDU 4405 期望DP
期望DP算是第一题吧...虽然巨水但把思路理理清楚总是好的.. 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落到a点时直接飞向b点.求走到n ...
- hdu 3853 概率dp
题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...
- HDU 4035 期望dp
这道题站在每个位置上都会有三种状态 死亡回到起点:k[i] 找到出口结束 e[i] 原地不动 p[i] k[i]+e[i]+p[i] =1; 因为只给了n-1条路把所有都连接在一起,那么我们可以自然的 ...
- HDU 3853 LOOPS:期望dp【网格型】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...
- HDU 3853 向下向右找出口问题-期望dp
题意:初始状态在(1,1)的位置.目标是走到(n,n).每次仅仅能向下向右或者不移动.已知在每一个格子时这三种情况的概率,每移动一步消耗2的魔力,求走到终点的使用的魔力的期望. 分析:简单的期望dp, ...
- 概率dp HDU 3853
H - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit ci ...
- HDU 4405 Aeroplane chess 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...
随机推荐
- Visual Studio 2017正式版离线安装方法
Visual Studio 2017 RTM正式版离线安装及介绍. 首先至官网下载:https://www.visualstudio.com/zh-hans/downloads/ VS 2017 正式 ...
- Vue2.0 新手完全填坑攻略——从环境搭建到发布
Jinkey原创感谢 showonne.yubang 技术指导Demo 地址:http://demo.jinkey.io/vue2源码:https://github.com/Jinkeycode/vu ...
- HDU 4745 Two Rabbits(区间DP,最长非连续回文子串)
Two Rabbits Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Total ...
- hive引入jar包--HIVE.AUX.JARS.PATH和hive.aux.jars.path
hive需要引入包时?该怎么引入? 一.hive-site.xml中的hive.aux.jars.path 此配置项对于hive server有效,但是是不会作用到hive shell.也就是说即使你 ...
- java 调用静态方法和构造函数和静态块执行的先后顺序
构造方法是只有你在new对象的时候才会执行,静态语句块和静态方法在类加载到内存的时候就已经执行了,另外,静态语句块只能给静态变量赋值,里面不能出现方法,同样,静态方法里面也不能出现静态语句块 追问: ...
- Redis持久化磁盘IO方式及其带来的问题
有Redis线上运维经验的人会发现Redis在物理内存使用比较多,但还没有超过实际物理内存总容量时就会发生不稳定甚至崩溃的问题 一.对Redis持久化的探讨与理解 redis是一个支持持久化的内存数据 ...
- centos7.3下ScyllaDB1.6安装
转自:http://10710016.blog.51cto.com/10700016/1900483 ScyllaDB 安装配置 1.说明: scylladb支持centos7.2 64位 及以上版本 ...
- fedora修改主目录文件名为英文
在gnome-terminal里面能够显示中文的,但是在文本终端里面中文都是不能显示的,是一个小小的正方形.因此可以只把主目录文件名换成英文的,方便文本终端命令输入,而其他的一些地方还是 ...
- GreenOpenPaint的实现(二)打开显示图片
1.DOC中添加,核心图片文件保存在这里.之所以不用Mat,是因为CVVImage有更好的输入输出函数. 我这里直接使用了public public: CvvImage m_image; 2.重载打开 ...
- Java实现:数据结构之排序
Java实现:数据结构之排序 0.概述 形式化定义:假设有n个记录的序列(待排序列)为{ R1, R2 , -, Rn },其相应的关键字序列为 { K1, K2, -, Kn }.找到{1,2, - ...