LOOPS

 
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

题意:

最开始他在Map[1][1],出口在Map[n][m];每一次他会消耗两颗神丹,然后每一个格子,有一定概率留在原地,有一定概率向下走一格,有一定概率向右走一格。。。求逃出去的神丹消耗期望。

思路:

dp[i][j]:从(i,j)到(n,m)的期望步数,所求答案即为dp[1][1]。

dp[i][j]=p1*dp[i][j]+p2*dp[i][j+1]+p3*dp[i+1][j](写的时候需要移项dp[i][j])

代码:

 #include"bits/stdc++.h"

 #define db double
#define ll long long
#define vl vector<ll>
#define ci(x) scanf("%d",&x)
#define cd(x) scanf("%lf",&x)
#define cl(x) scanf("%lld",&x)
#define pi(x) printf("%d\n",x)
#define pd(x) printf("%f\n",x)
#define pl(x) printf("%lld\n",x)
#define rep(i, n) for(int i=0;i<n;i++)
using namespace std;
const int N = 1e6 + ;
const int mod = 1e9 + ;
const int MOD = ;
const db PI = acos(-1.0);
const db eps = 1e-;
const ll INF = 0x3fffffffffffffff;
db p1[][];
db p2[][];
db p3[][];
db dp[][];
int n,m;
int main()
{ while(scanf("%d%d",&n,&m)==){
for(int i=;i<=n;i++)
for(int j=;j<=m;j++) cd(p1[i][j]),cd(p2[i][j]),cd(p3[i][j]);
memset(dp,, sizeof(dp));
for(int i=n;i>=;i--){
for(int j=m;j>=;j--){
if(dp[i][j]>eps) continue;
if(p1[i][j]>-eps) continue;
dp[i][j]=(p2[i][j]*dp[i][j+]+p3[i][j]*dp[i+][j]+)/(-p1[i][j]);
}
}
printf("%.3f\n",*dp[][]);
}
return ;
}

HDU3853 概率DP的更多相关文章

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

  2. [hdu3853]LOOPS(概率dp)

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

  3. 概率DP入门学习QAQ

    emmmm博客很多都烂尾了...但是没空写..先写一下正在学的东西好了 概率DP这东西每次考到都不会..听题解也是一脸懵逼..所以决定学习一下这个东东..毕竟NOIP考过...比什么平衡树实在多了QA ...

  4. 动态规划之经典数学期望和概率DP

    起因:在一场训练赛上.有这么一题没做出来. 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6829 题目大意:有三个人,他们分别有\(X,Y,Z\)块钱 ...

  5. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

  6. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  7. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

  8. POJ 2151 Check the difficulty of problems (概率DP)

    题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...

  9. 概率DP light oj 1030

    t组数据 n块黄金 到这里就捡起来 出发点1 到n结束  点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6  如果满6个的话 否则 ...

随机推荐

  1. 粗看ES6之JSON

    标签: es6 ES6新增JSON特性不是特别多,只是针对JSON某些情况下的写法上有一些优化: 当key值和value值对应变量名相同时 json对像中的方法书写 示例代码如下: <!DOCT ...

  2. apache管理命令

    常用的 httpd.exe -k [install(安装).uninstall(卸载).start(启动).stop(停止).restart(重启)] 说明:要执行命令,需进入到apache安装目录/ ...

  3. 从零开始的全栈工程师——js篇2.21(事件对象 arguments 阻止事件默认行为兼容 事件委托 事件源对象)

    一.事件对象 1.常用的事件2.每个元素身上的事件都是天生存在的 不需要我们去定义 只需要我们给这个事件绑定一个方法 当事件触发的时候就会执行这个方法 3.事件绑定的写法 ①div.onclick=f ...

  4. Angular搭建脚手架

    1.安装CLI: cnpm install -g @angular/cli //卸载: npm uninstall -g @angular/cli   npm cache clean 2.检测是否成功 ...

  5. form中action属性后面?传递参数 获取不到

    $p_id = $_REQUEST['p_id']; echo "<h1>您将更新商品编号为<span>$p_id</span>的商品信息 <a h ...

  6. 【干货】Html与CSS入门学习笔记9-11

    九.盒模型 与元素亲密接触 1.盒模型 css将每个元素都看做一个盒子,包括以下属性: 内容区content area:包含内容,内容可以决定大小,也可以自行设定宽度和高度.元素的width属性指定的 ...

  7. Win7安装软件,装到microsoft.vc90.crt时卡住的解决办法

    在安装某些程序的时候,可能会出现下列提示:an error occured during the installation of assembly ‘microsoft.vc90.crt,versio ...

  8. [原创]Debian9 从零编译配置Redis4.0

    序言 Redis 一.准备工作 1.1 更新系统安装包列表 没啥,就他喵想用个最新的. # apt update 1.2 创建需要使用的目录 创建目录source和web,分别用来放源码和编译后的文件 ...

  9. msql 综合练习

    8.统计列印各科成绩,各分数段人数:  课程ID,课程名称,[100-85],[85-70],[70-60],[<60] 尽管表面看上去不那么容易,其实用 CASE 可以很容易地实现: SELE ...

  10. eclipse 中 添加 tomcat后,启动访问时出现404

    1.切换到 server view. 2.双击出问题的 Server,出现如下页面. 3.选中Server,右键,点击选项卡的 Publish,就能进行编辑. 4.Server path 选中第二项: ...