HDU 3853:LOOPS(概率DP)
http://acm.split.hdu.edu.cn/showproblem.php?pid=3853
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.
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
题意:每一个格子有三个概率,分别是原地不动的概率,走到(i,j+1)的概率,走到(i+1,j)的概率,保证在边界的时候相对的概率为0,求从(1,1)走到(r,c)的期望。
思路:居然连圆神的题目都能出Orz,注意一个如果原地不动的概率为1要跳过。
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
#define N 1010 double dp[N][N];
double maze[N][N][]; int main()
{
int r, c;
scanf("%d%d", &r, &c);
while(~scanf("%d%d", &r, &c)) {
for(int i = ; i <= r; i++) {
for(int j = ; j <= c; j++) {
for(int k = ; k < ; k++) {
scanf("%lf", &maze[i][j][k]);
}
}
}
dp[r][c] = ;
for(int i = r; i > ; i--) {
for(int j = c; j > ; j--) {
if(j == c && i == r) continue;
if(maze[i][j][] == ) continue; // 坑点,如果为1的话会永远无法走出去
dp[i][j] = (maze[i][j][] * dp[i][j+] + maze[i][j][] * dp[i+][j] + ) / ((double) - maze[i][j][]);
}
}
printf("%.3f\n", dp[][]);
}
return ;
}
HDU 3853:LOOPS(概率DP)的更多相关文章
- HDU 3853 LOOPS 概率DP入门
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- HDU 3853 LOOPS 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...
- HDU 3853 期望概率DP
期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] , 右移:[x][y ...
- LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)
题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1 ...
- HDU 3853 LOOP (概率DP求期望)
D - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit St ...
- HDU 3853 LOOPS 可能性dp(水
在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
- 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 ...
随机推荐
- Java 线程池的介绍以及工作原理
在什么情况下使用线程池? 1.单个任务处理的时间比较短 2.将需处理的任务的数量大 使用线程池的好处: 1. 降低资源消耗: 通过重复利用已创建的线程降低线程创建和销毁造成的消耗.2. 提高响应速度: ...
- UTC时间与本地时间的相互转换
//把UTC时间转换成北京时间 DateTime now = DateTime.Parse(DateTime.UtcNow.ToString(), new CultureInfo("zh-C ...
- 获取git的最后一次提交的commit id
git log --pretty=format:"%h" | head -1 | awk '{print $1}' 可以放到xcode build setting post ...
- ASP.NET MVC Validation
CHECKBOX http://stackoverflow.com/questions/4934032/mvc3-make-checkbox-required-via-jquery-validate ...
- kfed (kernel file editor:内核文件编辑器)
kfed是没有在文档中标出的asm工具,在oracle 11gR1中被引入.可以被用来读写asm元数据,特别是磁盘头和asm元数据的内容. kfed是一个单独的工具,不依赖与asm实例,所以可以对mo ...
- Swift实战-豆瓣电台(一)准备
一 准备 我们现在看看我们要做一个什么样的东西 观看地址:http://v.youku.com/v_show/id_XNzI4ODY2Mjky.html 布局 通过上面这张图我们可以看出整个demo有 ...
- Lintcode: Product of Array Exclude Itself
Given an integers array A. Define B[i] = A[0] * ... * A[i-1] * A[i+1] * ... * A[n-1], calculate B wi ...
- git的基本使用
1.在本地新建一个文件夹来存放代码 2.用命令行进入这个文件夹 3.git init --来创建一个代码仓库 3. 配置用户信息:用户名和 邮箱(联系作者本人沟通, 责任到人) git config ...
- RF前端
加入LTE之后的多模多频需求: 在加入LTE后,不但要求终端在多模的基础上增加LTE工作频段,而且还要增加可以确保用户实现国际漫游的频段.然而 全球分配的LTE频段较多且较离散. 频段 上行工作频 ...
- IIS 浏览aspx页面出现 无法显示 XML 页
问题: 无法显示 XML 页. 使用 XSL 样式表无法查看 XML 输入.请更正错误然后单击 刷新按钮,或以后重试. 名称以无效字符开头.处理资源 'http://192.168.1.254:808 ...