HDU3853-LOOPS(概率DP求期望)
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 1864 Accepted Submission(s): 732
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
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
6.000
- #include <iostream>
- #include <cstdio>
- #include <cmath>
- #include <cstring>
- using namespace std;
- const int maxn = 1000+10;
- const int dx[3] = {0,0,1};
- const int dy[3] = {0,1,0};
- const double eps = 1e-8;
- double p[maxn][maxn][3];
- int r,c;
- double dp[maxn][maxn];
- bool isok(int x,int y){
- return x>=0&&x<r && y>=0&&y <c &&!(x==r-1&&y==c-1);
- }
- int main(){
- while(~scanf("%d%d",&r,&c)){
- for(int i = 0; i < r; i++){
- for(int j = 0; j < c; j++){
- for(int k = 0; k < 3; k++){
- scanf("%lf",&p[i][j][k]);
- }
- }
- }
- dp[r-1][c-1] = 0.0;
- for(int i = r-1; i >= 0; i--){
- for(int j = c-1; j >= 0; j--){
- double t = 2.0;
- for(int k = 1; k < 3; k++){
- int xx = i + dx[k];
- int yy = j + dy[k];
- if(isok(xx,yy)){
- t += dp[xx][yy]*p[i][j][k];
- }
- }
- if(fabs(1-p[i][j][0])<eps) dp[i][j] = 0;
- else dp[i][j] = t/(1-p[i][j][0]);
- }
- }
- printf("%.3lf\n",dp[0][0]);
- }
- return 0;
- }
HDU3853-LOOPS(概率DP求期望)的更多相关文章
- POJ2096 Collecting Bugs(概率DP,求期望)
Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...
- 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反向求期望 ...
- LightOJ 1030 【概率DP求期望】
借鉴自:https://www.cnblogs.com/keyboarder-zsq/p/6216762.html 题意:n个格子,每个格子有一个值.从1开始,每次扔6个面的骰子,扔出几点就往前几步, ...
- HDU-3853 LOOPS(概率DP求期望)
题目大意:在nxm的方格中,从(1,1)走到(n,m).每次只能在原地不动.向右走一格.向下走一格,概率分别为p1(i,j),p2(i,j),p3(i,j).求行走次数的期望. 题目分析:状态转移方程 ...
- HDU 3853 LOOP (概率DP求期望)
D - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit St ...
- HDU 4405 Aeroplane chess (概率DP求期望)
题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...
- HDU-4035 Maze (概率DP求期望)
题目大意:在一个树形迷宫中,以房间为节点.有n间房间,每间房间存在陷阱的概率为ki,存在出口的概率为ei,如果这两种情况都不存在(概率为pi),那么只能做出选择走向下一个房间(包括可能会走向上一个房间 ...
- HDU-4405 Aeroplane chess(概率DP求期望)
题目大意:一个跳棋游戏,每置一次骰子前进相应的步数.但是有的点可以不用置骰子直接前进,求置骰子次数的平均值. 题目分析:状态很容易定义:dp(i)表示在第 i 个点出发需要置骰子的次数平均值.则状态转 ...
随机推荐
- C#.NET中的CTS、CLS和CLR
以下内容来自:http://www.cnblogs.com/zagelover/articles/2741370.html 在学习.NET的过程中,都会不可避免地接触到这三个概念,那么这三个东西是什么 ...
- J2SE知识点摘记(二十一)
实现原理 前面已经提了一下Collection的实现基础都是基于数组的.下面我们就已ArrayList 为例,简单分析一下ArrayList 列表的实现方式.首先,先看下它的构造函数. 下列表格是在S ...
- SQL Server 2008 批量插入数据时报错
前几天在SQL Server 2008同步产品数据时,总是提示二进制文本被截断的错误,但是经过检查发现数据都符合格式要求. 百思不得其解,单独插入一条条数据则可以插入,但是批量导入则报错. 批量导入代 ...
- iOS开发基本须要
iOS开发基本须要 1 准备好对应的硬件和软件配置------基于Intel处理器的Mac操作系统 2 具有C++,Java或其它面向对象编程语言的开发经验 3 最新的iphone SDK的下 ...
- USB OTG简单介绍
1 引言 随着USB2.0版本号的公布,USB越来越流行,已经成为一种标准接口.如今,USB支持三种传输速率:低速(1.5Mb/s).全速(12Mb/s)和快速(480Mb/s),四种传输类型:块传输 ...
- NYOJ128 前缀式计算(栈的运用)
题目信息: http://acm.nyist.net/JudgeOnline/problem.php? pid=128 + 2 * + 3 4 5的值就是 37,详见输入输出. 输入 有多组測试数据, ...
- 散列表的实现 -- 数据结构与算法的javascript描述 第八章
散列表(哈希表 散列是一种常用的数据存储技术,散列后的数据可以快速地插入或取用. 散列表需要一个散列值(key)来存储指定数据,取数据也是依靠此. 散列值可以依靠计算数据的 ASCII码来获得,但是这 ...
- sass安装步骤
sass 基于Ruby,首先需要安装Ruby.当然也有node-sass,那是另外一种使用方式了.如果能FQ的,就不用看了,主要写给翻不了墙的人用. 1.安装Ruby,ruby下载地址: http:/ ...
- gulp脚本编写方法
建立一个gulpfile.js文件,内容直接抄gulp-htmlmin的readme: var gulp = require('gulp'); var htmlmin = require('gulp- ...
- ServiceStack 入门(二)
本文介绍创建一个简单的基于ServiceStack的项目. 1. 新建一个solution 2.创建完成后有4个project. ServiceModel是定义Request DTO 和 Reques ...