水概率DP。。。。

LOOPS

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 1359    Accepted Submission(s): 552

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
 
Source
 
Recommend
chenyongfu   |   We have carefully selected several similar problems for you:  3857 3854 3849 3850 3851 
 
 
 
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; double dp[][];
struct ppp
{
double stay,right,down;
}p[][]; const double eps=1e-; int r,c; int main()
{
while(scanf("%d%d",&r,&c)!=EOF)
{
memset(dp,,sizeof(dp));
for(int i=;i<=r;i++) for(int j=;j<=c;j++)
scanf("%lf%lf%lf",&p[i][j].stay,&p[i][j].right,&p[i][j].down);
for(int i=r;i>=;i--)
{
for(int j=c;j>=;j--)
{
if(i==r&&j==c) continue;
if(fabs(p[i][j].stay-.)<=eps) continue;
dp[i][j]=./(-p[i][j].stay)*(dp[i+][j]*p[i][j].down+dp[i][j+]*p[i][j].right+.);
}
}
printf("%.3lf\n",dp[][]);
}
return ;
}

HDOJ 3853 LOOPS的更多相关文章

  1. HDU 3853 LOOPS 期望dp

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

  2. 【HDU】3853 LOOPS

    http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意:n×m的格子,起始在(1,1),要求走到(n,m),在每一格(i,j)有三种走法,其中p[i,j,0 ...

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

    Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help ...

  4. HDU 3853 LOOPS 概率DP入门

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

  5. HDU 3853 LOOPS:期望dp【网格型】

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...

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

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

  7. hdu 3853 LOOPS(基础DP求期望)

    题目大意 有一个人被困在一个 R*C(2<=R,C<=1000) 的迷宫中,起初他在 (1,1) 这个点,迷宫的出口是 (R,C).在迷宫的每一个格子中,他能花费 2 个魔法值开启传送通道 ...

  8. hdu 3853 LOOPS 概率DP

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

  9. HDU 3853 LOOPS

    题意:对于每一格,都可以往右走,原地不走,往下走,概率分别为a[i],b[i],c[i](每一个格子与其他格子的概率不一定相同).在R*C的棋盘上(输入数据保证不会走出棋盘),求从(0, 0)走到(R ...

随机推荐

  1. 上班遇到的——关于Web安全

    恩只是流水账,内容写得可能比较随性,权当记录自己的成长:-D 今天经理特地开会跟我们讲了一下关于web安全的东西,SQL注入.文本编辑器.上传.本身程序权限管理漏洞 感觉好高级,做安全的人厉害,黑客也 ...

  2. Appium运行时,error: Logcat capture failed: spawn ENOENT的解决办法

    目前发现有以下两种可能: 一:查看环境变量是否配置成功. ANDROIDSDK D:\my_2_softwares\JAVA\adt-bundle-windows-x86-20140702\sdkPA ...

  3. 计算机图形学 - 图形变换(opengl版)

    作业题目: 图形变换:实现一个图形绕任意直线旋转的程序. 要求:把一个三维图形绕任意一条直线旋转,需要有初始图形,和旋转后的图形,最好也可以实时控制旋转. 最少要做出绕z轴旋转. 原理:http:// ...

  4. Python基本数据类型之str

    一.创建 s = "morra" s = str("morra") #str()这种方法会自动找到str类里的_init_方法去执行 ------------- ...

  5. 网络存储(二)之ISCSI原理

    组成 一个简单ISCSI系统大致由以下部分构成 ISCSI Initiator 或者 ISCSI HBA ISCSI Target 以太网交换机 一台或者多台服务器 结构图如下: iscsi服务器用来 ...

  6. Altium Designer 15 --- Nets Update

    Now I want to introduce the use of 'Configure Physical Nets', as follows: If you has finished the PC ...

  7. css006 文本格式化

    css006 文本格式化 文本格式化:字体(font-family).颜色(color).字号(font-size). 行距(line-height).粗体(font-weight).斜体(font- ...

  8. phpcms后台获取当前登录账号的数据

    $amdinid=$_SESSION['userid'];$infoadmin=$this->admin->get_one(array('userid'=>$amdinid)); v ...

  9. accept()

    在一个套接口接受一个连接.accept()是c语言中网络编程的重要的函数,windows系统在#include<winsock.h> ,而linux系统在#include <sys/ ...

  10. ecshop默认配置

    手机端 1.C, 系统默认所有配置 输出:print_r(C())