HDU3853LOOPS (师傅逃亡系列•三)(基础概率DP)
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];每一次他会消耗两颗神丹,然后每一个格子,有一定概率留在原地,有一定概率向下走一格,有一定概率向右走一格。。。求师傅逃出去的神丹消耗期望。
思路:
这次的逃亡很好想,没有前两次那样需要逆推或者求公式。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
using namespace std;
double dp[][],a[][][];
int main()
{
int n,m,i,j,k;
while(~scanf("%d%d",&n,&m)){
for(i=;i<=n;i++)
for(j=;j<=m;j++)
for(k=;k<;k++)
scanf("%lf",&a[i][j][k]);
memset(dp,,sizeof(dp));
for(i=n;i>=;i--)
for(j=m;j>=;j--)
{
if(fabs(-a[i][j][])<1e-)//停留原地的概率为1
continue;
dp[i][j]=(dp[i][j+]*a[i][j][]+dp[i+][j]*a[i][j][]+)/(1.0-a[i][j][]);
}
printf("%.3f\n",dp[][]);
}return ;
}
HDU3853LOOPS (师傅逃亡系列•三)(基础概率DP)的更多相关文章
- ZOJ3640Help Me Escape(师傅逃亡系列•一)(数学期望||概率DP)
Background If thou doest well, shalt thou not be accepted? and if thou doest not well, sin lieth at ...
- HDU4035 Maze(师傅逃亡系列•二)(循环型 经典的数学期望)
When wake up, lxhgww find himself in a huge maze. The maze consisted by N rooms and tunnels connecti ...
- 【整理】简单的数学期望和概率DP
数学期望 P=Σ每一种状态*对应的概率. 因为不可能枚举完所有的状态,有时也不可能枚举完,比如抛硬币,有可能一直是正面,etc.在没有接触数学期望时看到数学期望的题可能会觉得很阔怕(因为我高中就是这么 ...
- 概率dp小结
好久之前学过,记得是一次亚洲区的前几天看了看概率dp,然后亚洲区就出了一道概率dp,当时虽然做上了,但是感觉有很多地方没懂,今天起早温习了一下,觉得很多地方茅塞顿开,果然学习的话早上效果最好了. 首先 ...
- HDU3853-LOOPS(概率DP求期望)
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Su ...
- java基础系列(三)---HashMap
java基础系列(三)---HashMap java基础系列 java基础系列(一)---String.StringBuffer.StringBuilder java基础系列(二)---Integer ...
- java基础解析系列(三)---HashMap
java基础解析系列(三)---HashMap java基础解析系列 java基础解析系列(一)---String.StringBuffer.StringBuilder java基础解析系列(二)-- ...
- 【C++自我精讲】基础系列三 重载
[C++自我精讲]基础系列三 重载 0 前言 分二部分:函数重载,操作符重载. 1 函数重载 函数重载:指在同一名字空间中,函数名称相同,参数类型.顺序或数量不同的一类函数,同一函数名的函数能完成不同 ...
- [转]概率DP总结 by kuangbin
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...
随机推荐
- windchill10.0&11.0API_chm版百度云
windchill10.0版本和11.0版本的javadoc,也就是api 文件内容 windchill10.0.chm版本的 windchill10.0api.chm版本 百度云链接(免费推荐) 链 ...
- Python学习札记(三) I/O
参考:输入和输出 I/O 1.print()函数 a.调用print()输出字符串有以下两种方式:(1)print('[字符串]') (2)print("[字符串]") b.调用p ...
- Enter键禁止表单提交
Enter键禁止表单提交js代码: //禁用Enter键表单自动提交 document.onkeydown = function (event) { var target, code, tag; if ...
- ZooKeeper的API操作(二)(通俗易懂)
所需要6个jar包,都是解压zookeeper的tar包后里面的. zookeeper-3.4.10.jar jline-0.094.jar log4j-1.2.16.jar netty- ...
- C#忽略decimal多余的0
decimal test=1.2000:test.ToString("0.####");
- 【Linux】无法添加用户,报“useradd: cannot open /etc/passwd”问题解决过程记录
问题描述 今天在一个新的Linux环境添加用户的时候,发现不能添加,遇到了以下错误 useradd: cannot open /etc/passwd 解决方法 用lsattr命令查看/etc/pass ...
- 由angular命令行工具(angular-cli)生成的目录和文件
e2e目录:是端到端的测试目录,包含基本的测试桩.是用来做自动测试的. src:应用源代码目录.我们写的所有代码都应该在这里面. app:包括应用的组件和模块.我们自己写的绝大部分代码都是写在这个目录 ...
- php给图片添加圆角并且保持透明,可做圆形头像
原文链接:https://www.zhaokeli.com/article/8031.html 给图片添加圆角, 用到的主要的(判断一个点是否在圆内)的公式在上面所说的生成圆形图片文章中. 然后扫 ...
- ABP 学习问题集锦
一:Update-Database : 无法将“Update-Database”项识别为 cmdlet.函数.脚本文件或可运行程序的名称的问题 解决: 这是因为没有引用EntityFramework命 ...
- webstrom 配置eslint 自动修复错误
1.展示效果 如何给vue项目添加eslint呢,如何自动修复呢? 先展示一下效果: 2.配置步骤 1.安装插件ESLint plugin webstrom 其实有个非常好用的插件,ESLint pl ...