H - LOOPS

Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d
& %I64u

Appoint description: 
System Crawler  (2014-10-22)

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的矩阵,起点在(1,1),终点在(R。C),告诉你在每一个点在原地。向右,向下的概率,每次花费2个能量去移动(呆在原地也可)。求到达终点的能量花费期望。

本题须要注意题目说期望小于1e6,那么呆在那个点的概率为1的点肯定从起点出发不可达的点。

否则期望会无穷大。

dp[i][j]表示从(i,j)到(r,c)所须要的期望能量。

/*************************************************************************
> File Name: t.cpp
> Author: acvcla
> Mail: acvcla@gmail.com
> Created Time: 2014年10月21日 星期二 21时33分55秒
************************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<set>
#include<math.h>
using namespace std;
typedef long long LL;
const int maxn = 1e3 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
double dp[maxn][maxn];
int r,c;
double Div(int a,int b){
return double(a)/b;
}
struct p
{
double p1,p2,p3;
}P[maxn][maxn];
int main(int argc, char const *argv[])
{
while(~scanf("%d%d",&r,&c)){
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
scanf("%lf%lf%lf",&P[i][j].p1,&P[i][j].p2,&P[i][j].p3);
}
}
//memset(dp,0,sizeof dp);
dp[r][c]=0;
for(int i=r;i>=1;i--)
for(int j=c;j>=1;j--){
dp[i][j]=0;
if(i==r&&j==c||P[i][j].p1==1)continue;
dp[i][j]=(dp[i+1][j]*P[i][j].p3+dp[i][j+1]*P[i][j].p2+2)/(1-P[i][j].p1);
}
printf("%.3f\n",dp[1][1]);
}
return 0;
}

概率dp HDU 3853的更多相关文章

  1. 概率DP hdu 3366 .

    题意:一个人被困在一个城堡里,面前有n条路,他自己有m百万元,选择每一条路都有p概率通过,q概率遇到士兵,1-p-q概率道路不通:遇到士兵的话需要上交1百万,如果不够钱,则被杀死,问的是最优情况下多少 ...

  2. 概率dp HDU 4405

    Aeroplane chess Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

  3. [概率dp] hdu 5378 Leader in Tree Land

    题意: 给你一颗以1位根节点的树.我们定义对于每一个子树,节点权值最大的权值记为这个子树的权值,为你将1~n放到这个树里 满足最大权值仅仅有k个的组合数是多少. 思路: 我们能够知道以每一个节点为子树 ...

  4. 概率DP HDU 4586 play the dice

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4586 解题思路: 只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加. ...

  5. hdu 3853 LOOPS 概率DP

    简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  6. HDU 3853 期望概率DP

    期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] ,  右移:[x][y ...

  7. hdu 3853 概率dp

    题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...

  8. HDU 3853 LOOPS 概率DP入门

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total Sub ...

  9. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

随机推荐

  1. bat脚本启动exe并打开文件后退出 + 中文乱码

    写了个脚本用于复制模板到新的cpp文件. 将脚本路径加到环境变量里,只需在cmd窗口输入“new hdu 1419”,就会自动将模板拷贝到WORK_DIR下的hdu文件夹内一个名叫"1419 ...

  2. servlet中Session的用法

    ## (1)什么是Session? 服务器端为了保存用户的状态而创建的一个特殊的对象(即session对象).          当浏览器第一次访问服务器时,服务器会创建session对象(该    ...

  3. GDOI2018爆炸记

    Day0 12:45p.m. 从初中部出发前回班探望了一下同学,受到热烈欢迎(?) 13:15p.m. 出发去中山,路上本来想用mac看fz的,结果ass字幕导入失败,心态爆炸*1:后来成功获取xfz ...

  4. HDU 4069 数独

    好久没做题了,建图搞了好久…… 然后,判是否有多解的时候会把原来的答案覆盖掉…… 这里没注意,弄了一下午…… 代码: #include <iostream> #include <cs ...

  5. Jquery-基础知识点

    jquery 包含的功能 1.HTML元素选取.操作 2.CSS操作 3.HTML事件函数 4.Javascript特效和动画 5.HTML DOM遍历和修改 6.AJAX 7. Untilities ...

  6. java用freemarker实现导出word----包含图片

    分为以下三个步骤: 1.先制作word模板 2.将该文档另存为 xml 文件 3.打开xml 文件 将对应的字段替换,比如 4.将xml文件保存成ftl格式的文档 5.相应的代码: package o ...

  7. uva live 2326 - Moving Tables

    把房间号映射在一条坐标上,然后排序,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划,最后找从左到右找一次可行的计划, ............ 次数*1 ...

  8. quick-cocos2d-x游戏开发【2】——项目结构分析、创建新场景

    创建完一个新项目之后,我们能够简单的看一看这个项目的文件组成,有这么一个文件层次结构 几个proj.*目录就不用说了,是相应的平台的解决方式,res专门存放我们的游戏资源.scripts存放我们的lu ...

  9. 我是怎么利用微信做兼职月入1W的

    物价上涨.导致非常多人都感觉如今的收入入不敷出,有的是迫于生活压力.有的是为了提高生活质量,等等都想好好利用业余时间来做点兼职,当然我也不例外.正好笔者在微信刚推出一段时间的时候利用微信来做点兼职赚点 ...

  10. 【翻译自mos文章】开启dblink的 oracle net trace/tracing --对dblink进行跟踪的方法

    开启dblink的 oracle net trace/tracing --对dblink进行跟踪的方法. 參考原文: DBLINK: How to Enable Oracle Net Tracing ...