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 ...
随机推荐
- Linux 内核版本规律
版本组成:主版本号.次版本号.修正版本号 主版本号和次版本号一起标志着重要的功能变更,修正版本号表示较小的功能变更.次版本号表示该版本是否为稳定版本,偶数则为稳定版本,奇数则可能存在一些BUG.
- bind: address already in use
2016/04/18 09:46:06 server.go:36: listen at 0.0.0.0:9530 2016/04/18 09:46:06 server.go:39: listen er ...
- ios提示框,自动消失
-(void)click { NSString *showMsg = @"点击我,开始提示"; int width = showMsg.length * 20; UIWindow ...
- Synchronized及其实现原理
并发编程中synchronized一直是元老级角色,我们称之为重量级锁.主要用在三个地方: 1.修饰普通方法,锁是当前实例对象. 2.修饰类方法,锁是当前类的Class对象. 3.修饰代码块,锁是sy ...
- IntelliJ IDEA 缓存和索引介绍和清理方法
IntelliJ IDEA 首次加载项目的时候,都会创建索引,而创建索引的时间跟项目的文件多少成正比,我也简单强调了 IntelliJ IDEA 索引的重要性.这里我们再对此进行详细说明索引.缓存对 ...
- 实验十四_访问CMOS RAM
编程:以"年/月/日 时:分:秒"的格式,显示当前的日期,时间. 注意:CMOS RAM中存储着系统的配置信息,除了保存时间信息的单元外,不要向其他的单元写入内容,否则将引起一些系 ...
- 转:Tomcat配置
一.修改Tomcat端口号步骤: 1.找到Tomcat目录下的conf文件夹 2.进入conf文件夹里面找到server.xml文件 3.打开server.xml文件 4.在server.xml文件里 ...
- 树形dp Anniversary party(HDU1520)
题意:给出一棵树,(上下级关系)每个节点都有一个权值,要求选出一些节点满足这些节点任意连个点都不是直接的上下级关系,可以得到的最大权值是多少? 分析:对于每个点有两个状态选或者不选,用状态数组dp[u ...
- ASP.NET的一般处理程序对数据的基本操作
TableList.ashx: <%@ WebHandler Language="C#" Class="TableList" %> using Sy ...
- Android异步任务AsyncTask
package com.example.asynctask; import java.net.MalformedURLException; import java.net.URL; import an ...