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. NYOJ 16 矩形嵌套【DP】

    解题思路:呃,是看的紫书上面的做法,一个矩形和另一个矩形之间的关系就只有两种,(因为它自己是不能嵌套自己的),可嵌套,不可嵌套,是一个二元关系,如果可嵌套的话,则记为1,如果不可嵌套的话则记为0,就可 ...

  2. SpringBoot 获取客户端 ip

    /** * 获取客户端ip地址 * @param request * @return */ public static String getCliectIp(HttpServletRequest re ...

  3. 【转载】CPU架构、指令集与指令集体系结构(ISA)

    最近学习计算机系统基础,了解到指令集体系结构. 对CPU架构.指令集和指令集体系结构的关系不清楚,特此记录. 指令集体系结构(ISA)包括 指令集.指令集编码.基本数据类型等. CPU架构 实现了 指 ...

  4. java 获取config 配置文件

    static ResourceBundle PropertiesUtil = ResourceBundle.getBundle("config"); public static S ...

  5. FTP 无法获取目录列表的处理方法

    FTP 无法获取目录列表的处理方法 1.以阿里云的服务器为例 对于阿里云的服务器是因为阿里云为了进一步保护用户的安全利益使用了安全策略组,我们要设置安全策略组对应的端口开启. 首先要设置端口范围,这个 ...

  6. yum-config-manager --add-repo=

    [root@server0 yum.repos.d]# yum-config-manager --add-repo=ftp://192.168.31.121/centos7u4Loaded plugi ...

  7. pandas 5 导入导出 读取保存 I/O API

    官网The pandas I/O API pickle格式是python自带的 from __future__ import print_function import pandas as pd da ...

  8. nginx 1.5 支持websocket

    proxy_pass http://backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set ...

  9. Android Jni 调用

    Chap1:JNI完全手册... 3 Chap2:JNI-百度百科... 11 Chap 3:javah命令帮助信息... 16 Chap 4:用javah产生一个.h文件... 17 Chap5:j ...

  10. php中的页面跳转和重定向

    php中的页面跳转和重定向 ThinkPHP中跳转和重定向的区别 跳转: 浏览器认为: 当前URL请求成功, 重新请求新的URL. 浏览器会 记录当前的URL 和 新的URL 在请求历史记录中. 回退 ...