水概率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. JSONArray的使用

    用的是fastjson.jar包 1. jsonarray,jsonobject 使用正确代码如下:(这种getJSONObject 函数形成jsonobj 的方式非常好,可以避免循环引用或jsono ...

  2. Mysql学习笔记(三)对表数据的增删改查。

    正文内容. 这一部分是最简单的,也是最麻烦的.简单是因为其实只包括增删该插四个部分.大体上看,增加数据.删除数据.修改数据.查询数据都不麻烦啊,我们日常都是常用的.这个谁不会呢?以前在培训机构学mys ...

  3. 公共事件处理函数js库

    var EventUtil = { /* *添加事件处理 参数:元素对象 事件类型 处理函数 */ addHandle: function (element, type, handle) { //do ...

  4. python 处理CSV数据

    从CS中导入数据 Python中有一个CSV模块支持读写各种方言格式的CSV文件.方言是很重要的,因为没有一个同意的CSV标准,不同的应用实现CSV的方式略有不同,当看到文件的内容的时候你往往很容易第 ...

  5. JS-百钱买百鸡案例-for循环制作

    <html> <head> <meta charset="utf-8"/> <title></title> <sc ...

  6. 面向服务架构(SOA)和企业服务总线(ESB)

    http://www.cnblogs.com/shanyou/archive/2008/04/19/1161452.html 学习和研究在企业中实施面向服务架构(SOA),简单回顾SOA和ESB,重点 ...

  7. javascript序列化

    JSON.stringify() JSON.parse() toJSON() var person={"cardId":"546651353435"}; con ...

  8. datatable group by

    对datatable 里面的数据按某一特定的栏位进行分组并且按照某一规则 var query = from t in rate.AsEnumerable()   group t by new { t1 ...

  9. Linux下显示IP地理位置信息的小工具-nali

    一.简介 nali,名字取自中文“哪里”的拼音.nali包含一组命令行程序,其主要功能就是把一些网络工具的输出的IP字符串,附加上地理位置信息(使用纯真数据库QQWry.Dat).例如74.125.1 ...

  10. 15款优秀移动APP产品原型设计工具

    一新来小盆友问:“移动产品原型设计都用啥工具?” 答:“@#¥……&%*” 又问:“能详细说下各个工具吗?我比较一下” “……” 好吧,谁让我那么的爱分享而你又是小美女呢 ———————正文开 ...