水概率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. Zabbix3.2安装部署

    zabbix server 前提环境: CentOS6 Lnmp php需要的包(bcmath,mbstring,sockets,gd,libxml,xmlwriter,xmlreader,ctype ...

  2. C#把数据写到硬盘指定位置

    FileStream fs; StreamWriter sw;string RootPath = @"C:\Advantech" + "\\tempData\\" ...

  3. java 环境变量 设置 问题

    问题按照网上教程配置好了  tomcat可以用了.但是发现java不能用. 网上教程(类似教程太多了 ,就不 具体说了 http://jingyan.baidu.com/article/f96699b ...

  4. Linux下shell脚本中信号捕获和函数练习脚本之ping一个网段

    该脚本主要的目的是练习在Linux bash脚本中捕获信号,顺便练习一下函数的使用,还有就是终止一个正在运行的程序后,该程序打开的文件的后续处理问题等等!脚本功能:  ping一个网段内的IP,检测哪 ...

  5. POJ1080Human Gene Functions(LCS变形)

    题目链接 题目:给出两个串,每匹配一种有一种权值,求权值最大的匹配串 就是 最长公共子序列的 的思想: 首先对于 i 和 j 来比较, 一种情况是i和j匹配,此时 dp[i][j] = dp[i - ...

  6. struts2文件目录结构

    apps 文件夹包含了多个 example 示例应用的压缩包. docs 文件夹包含了 struts 官方的帮助文档. lib 文件夹包含了 struts 提供的类库 jar 包. src 文件夹包含 ...

  7. 使用BPEL创建Web服务组合

    http://www.cnblogs.com/ahhuiyang/archive/2012/12/18/2824131.html 为简单起见,本例的Web服务组合只调用一个Web Service AP ...

  8. java中"与"和"或"

    在java中"与"和"或"都具有短路功能. 关于"或"运算如 if(mc == null || mc.getReceive()==0){ / ...

  9. uC/OS-II类型定义

    /*************************************************************************************************** ...

  10. 将字符串转化为数字(Convert和Parse的用法)

    字符串必须是数字,不要超过转换成目标数字类型的范围.超过的话系统也会报错(溢出). static void Main(string[] args) { string s; int i; Console ...