LOOPS

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)

Total Submission(s): 1864    Accepted Submission(s): 732

Problem Description
Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl).



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.








 
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
 

  题意:有R*C个格子,一个家伙要从(0,0)走到(R-1,C-1) 每次仅仅有三次方向,各自是不动,向下,向右,告诉你这三个方向的概率,以及每走一步须要耗费两个能量,问你走到终点所须要耗费能量的数学期望:

思路:非常裸的概率DP求期望,仅仅是有一个坑点要注意,就是当分母为0的时候,浮点数仅仅会出现NAN,而不会像整形那样报RE!

#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求期望)的更多相关文章

  1. POJ2096 Collecting Bugs(概率DP,求期望)

    Collecting Bugs Ivan is fond of collecting. Unlike other people who collect post stamps, coins or ot ...

  2. 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 ...

  3. [hdu3853]LOOPS(概率dp)

    题意:迷宫是一个R*C的布局,每个格子中给出停留在原地,往右走一个,往下走一格的概率,起点在(1,1),终点在(R,C),每走一格消耗两点能量,求出最后所需要的能量期望. 解题关键:概率dp反向求期望 ...

  4. LightOJ 1030 【概率DP求期望】

    借鉴自:https://www.cnblogs.com/keyboarder-zsq/p/6216762.html 题意:n个格子,每个格子有一个值.从1开始,每次扔6个面的骰子,扔出几点就往前几步, ...

  5. HDU-3853 LOOPS(概率DP求期望)

    题目大意:在nxm的方格中,从(1,1)走到(n,m).每次只能在原地不动.向右走一格.向下走一格,概率分别为p1(i,j),p2(i,j),p3(i,j).求行走次数的期望. 题目分析:状态转移方程 ...

  6. HDU 3853 LOOP (概率DP求期望)

    D - LOOPS Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit St ...

  7. HDU 4405 Aeroplane chess (概率DP求期望)

    题意:有一个n个点的飞行棋,问从0点掷骰子(1~6)走到n点须要步数的期望 当中有m个跳跃a,b表示走到a点能够直接跳到b点. dp[ i ]表示从i点走到n点的期望,在正常情况下i点能够到走到i+1 ...

  8. HDU-4035 Maze (概率DP求期望)

    题目大意:在一个树形迷宫中,以房间为节点.有n间房间,每间房间存在陷阱的概率为ki,存在出口的概率为ei,如果这两种情况都不存在(概率为pi),那么只能做出选择走向下一个房间(包括可能会走向上一个房间 ...

  9. HDU-4405 Aeroplane chess(概率DP求期望)

    题目大意:一个跳棋游戏,每置一次骰子前进相应的步数.但是有的点可以不用置骰子直接前进,求置骰子次数的平均值. 题目分析:状态很容易定义:dp(i)表示在第 i 个点出发需要置骰子的次数平均值.则状态转 ...

随机推荐

  1. 0x800a138f - JavaScript runtime error: Unable to get property 'asSorting' of undefined or null reference 错误原因以及解决办法

    使用Jquery Datatables的时候也许会碰到这样的错误提示,当我们仔细的查找代码,发现引用的js文件,css文件均引用了,就是找不到他的问题所在. 这是从我们引用的js文件内部报的错. 这个 ...

  2. 【Chromium中文文档】插件架构

    插件架构 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Plugin_A ...

  3. 对Msn协议的一点点研究

    这个也是好奇msn的协议还是2011年的时候写的, 就在网上找啊找啊, 可惜要不是不能用就是C++代码还有就是不完整, 到最后我也没弄成功,只到了下面这步就挂掉了...... 登录成功<=SBS ...

  4. 计算机世界的道(C/ASM)生一(OS),一生二(API),二生万象(MFC/COM)——学包装技术的程序员将来会损失比较大,因为不了解本质,一旦包装过时就会被淘汰

    道生一,一生二,二生万象.OO的思想就是抽象,万象归宗,化繁为简.99%的程序员使用OO,或者所谓的类库的目的就是好用,不必了解内部实现就可以直接达到所期望的结果.这时一种生产力的进步,一种流水线式半 ...

  5. JavaEE Tutorials (16) - Java消息服务概念

    16.1JMS API概述198 16.1.1什么是消息传送198 16.1.2什么是JMS API199 16.1.3何时使用JMS API199 16.1.4Java EE平台如何使用JMS AP ...

  6. js类方法,对象方法,原型的理解(转)

    function People(name) { this.name=name; //对象方法 this.Introduce=function(){ alert("My name is &qu ...

  7. poj1651 最优矩阵乘法动态规划解题

    题目描述: 有若干个矩阵{Ai},元素都为整数且已知矩阵大小. 如果要计算所有矩阵的乘积A1 * A2 * A3 .. Am,最少要多少次整数乘法? 输入 第一行一个整数n(n <= 100), ...

  8. Android_Intent意图详解

    本博文为子墨原创,转载请注明出处! http://blog.csdn.net/zimo2013/article/details/11863857 1.Intent作用 Intent是一个将要执行的动作 ...

  9. 如何在VMware虚拟机上安装Linux操作系统(Ubuntu)

    作为初学者想变为计算机大牛非一朝一夕,但掌握基本的计算机操作和常识却也不是多么难的事情.所以作为一名工科男,为了把握住接近女神的机会,也为了避免当白痴,学会装系统吧!of course为避免把自己的电 ...

  10. IOS开发之Cocoa编程—— NSUndoManager

    在Cocoa中使用NSUndoManager可以很方便的完成撤销操作.NSUndoManager会记录下修改.撤销操作的消息.这个机制使用两个NSInvocation对象栈. NSInvocation ...