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. c#学习0217

    1 继承 继承 1 子类是否继承了父类的构造函数 答案:子类并没有继承父类的构造函数 但是子类或默认调用父类的无参数的构造函数 在子类中创建父类对象 这样子类才可以使用父类的成员 如果在父类中声明了有 ...

  2. 微信小程序------开发测试

    一.注册小程序 注:微信小程序注册的邮箱不能被其他微信公众平台注册,未被微信开放平台注册,未被给人微信号绑定的微信号. 二.注册完小程序后,下载开发者工具 开发者工具的使用: 1.打开开发者工具:用已 ...

  3. SpringBoot学习笔记(7)-----CORS支持解决跨域问题

    在实际应用开发中,跨域是一个比较常见的问题,解决方法可以用jsonp,frame,cors等, 这里示例的是SpringBoot对CORS的支持的三种实现方式 第一种:配置一种全局的支持,这种方式需要 ...

  4. 将对象a的属性赋值给对象b

    BeanUtils.copyProperties(a,b); 将a的属性赋值给b(ab的共同属性)

  5. jq 遍历 元素

    $("#spec").find("div.gods-spe").each(function(i,n){ var child = $(this).children ...

  6. The Zen of Python, by Tim Peters

    Beautiful is better than ugly. Explicit is better than implicit. Simple is better than complex. Comp ...

  7. Git 修改commit message

    1.git log --oneline -5 查看最近5次commit的简要信息,输出信息为:简短commitID commit_message,可以根据需要查看最近n次的提交 也可以git log ...

  8. C++容器(五):set类型

    set类型 map容器是键-值对的集合,好比以任命为键的地址和电话号码.而set容器只是单纯的键的集合.当只想知道一个值是否存在时,使用set容器是最适合. 使用set容器必须包含set头文件: #i ...

  9. cogs 141. [USACO Jan08] 奶牛的选举

    141. [USACO Jan08] 奶牛的选举 ★   输入文件:elect.in   输出文件:elect.out   简单对比时间限制:1 s   内存限制:16 MB 在推翻了Farmer J ...

  10. 最多包含2/k个不同字符的最长串

    看这里的解答: http://www.cnblogs.com/grandyang/p/5351347.html 通用解决了2和k的问题.