http://acm.split.hdu.edu.cn/showproblem.php?pid=3853

LOOPS

Problem 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

题意:每一个格子有三个概率,分别是原地不动的概率,走到(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)的更多相关文章

  1. HDU 3853 LOOPS 概率DP入门

    LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total Sub ...

  2. hdu 3853 LOOPS 概率DP

    简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...

  3. hdu 3853 LOOPS (概率dp 逆推求期望)

    题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Tota ...

  4. HDU 3853 LOOPS 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...

  5. HDU 3853 期望概率DP

    期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] ,  右移:[x][y ...

  6. LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)

    题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1 ...

  7. HDU 3853 LOOP (概率DP求期望)

    D - LOOPS Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit St ...

  8. HDU 3853 LOOPS 可能性dp(水

    在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...

  9. HDU 3853LOOPS(简单概率DP)

    HDU 3853    LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...

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

随机推荐

  1. Oracle表名、列名、约束名的长度限制

    Oracle数据库版本11.2.0.1.0 Oracle表名.列名.约束名的长度限制 1.查询用户所有的表 select * from USER_TABLES; 2.查询用户所有表的列 select ...

  2. 获取Json数据某节点的值

    时间匆忙,直接上代码,回家还得做清蒸鱼呢! #region 获取Json字符串某节点的值 /// <summary> /// 获取Json字符串某节点的值 /// </summary ...

  3. Oracle 监听器日志文件过大导致监听异常

    Oracle 监听器日志文件过大导致监听异常 db版本:11.2.0.1 os版本:windows2008 现象: 应用异常,无法连接数据库.登陆数据库服务器,查看监听已经断掉.尝试重启监听,重启失败 ...

  4. zabbix添加邮件报警机制

    zabbix添加邮件报警机制 作者:尹正杰 还记得之前跟大家聊过的一个如何监控一个目录的话题吗?我们虽然监控出来数据了,也有数据了,但是,只是监控也没有用啊~因为我们不能24小时盯着屏幕然后 出了事情 ...

  5. CentOS 7 内核更新后删除旧内核

    0.当前 # uname -sr Linux -.el7.x86_64 1.搜索查询 # rpm -q kernel kernel--.el7.x86_64 kernel--.el7.x86_64 k ...

  6. ajax常用参数

    url: 要求为String类型的参数,(默认为当前页地址)发送请求的地址.前台跳转到后台 请求参数:前台向后台传数据 回调函数:回调函数就是一个自定义的函数在发生特定的事件的时候调用来处理这个事件 ...

  7. HashMap和HashTable区别

    HashMap和HashTable区别 HashMap--->允许控制/线程安全 HashTable-->线程不安全

  8. paper 23 :Kullback–Leibler divergence KL散度(2)

    Kullback–Leibler divergence KL散度 In probability theory and information theory, the Kullback–Leibler ...

  9. angular form 验证 ngMessage

    <!DOCTYPE HTML> <html ng-app="deliciousApp"> <head> <meta charset=&qu ...

  10. 关于teleport_pro使用过程中的一点疑惑

    在我新建工程的时候,有两个选项,一个是"new project wizard"另一个是"new project",然后就纠结了,我应该使用那个呢? 使用第一个的 ...