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

LOOPS

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

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
等于1的时候就要continue;
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
double e[][];
struct node
{
double p1,p2,p3;
}a[][];
int main()
{
int r,c,i,j;
while(~scanf("%d%d",&r,&c))
{
memset(e,,sizeof(e));
for(i=;i<=r;i++)
for(j=;j<=c;j++)
{
scanf("%lf%lf%lf",&a[i][j].p1,&a[i][j].p2,&a[i][j].p3);
}
e[r][c]=;
for(i=r;i>=;i--)
{
for(j=c;j>=;j--)
{
if(i==r&&j==c)
continue;
if(a[i][j].p1==)
continue;
e[i][j]=double(a[i][j].p2*e[i][j+]+a[i][j].p3*e[i+][j]+)/double(-a[i][j].p1); }
}
printf("%.3lf\n",e[][]);
}
return ;
}
 

HDU-3854 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(概率 dp 期望)

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

  3. HDU 3853 LOOPS 概率DP入门

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

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

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

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

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

  6. HDU 3854 Glorious Array(树状数组)

    题意:给一些结点,每个结点是黑色或白色,并有一个权值.定义两个结点之间的距离为两个结点之间结点的最小权值当两个结点异色时,否则距离为无穷大.给出两种操作,一种是将某个结点改变颜色,另一个操作是询问当前 ...

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

  10. HDU 3853 LOOPS 可能性dp(水

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

随机推荐

  1. Visual 2012 常用快捷键

    快捷键 功能说明 Crtl+K,Crtl+C 注释光标所在行,或选中行 Crtl+K,Crtl+U 反注释光标所在行,或选中行 Crtl+K,Crtl+F 格式化全文 F12 转到定义 Shift + ...

  2. A题笔记(4)

    No. 1384 这题没啥 不过网考成绩出了,发现我的口语分数相较其他人还挺高的~~~哈哈哈 Code::Blocks 有时在程序运行结束后,.exe 并没有结束,因而之后无论怎么调试和修改代码,运行 ...

  3. jQuery 遍历祖先

    祖先是父.祖父或曾祖父等等. 通过 jQuery,您能够向上遍历 DOM 树,以查找元素的祖先. 向上遍历 DOM 树 这些 jQuery 方法很有用,它们用于向上遍历 DOM 树: parent() ...

  4. AngularJS cookie的使用

    Javascript使用document.cookie接口来处理简单的文本cookie,但现在大多数现代浏览器都可以使用html5 API了(sessionstorage和localstorage), ...

  5. 读书笔记之 - javascript 设计模式 - 装饰者模式

    本章讨论的是一种为对象增添特性的技术,它并不使用创建新子类这种手段. 装饰者模式可以透明地把对象包装在具有同样接口的另一对象之中,这样一来,你可以给一些方法添加一些行为,然后将方法调用传递给原始对象. ...

  6. jQuery插件综合应用(三)发布文章页面

    一.使用的插件 一个折叠的功能导航,由Akordeon插件实现.Nanoscroller插件与Tagit插件主要用于美化页面.这里只是测试,其实还可以综合使用其它的插件,例如将Akordeon插件换成 ...

  7. winform程序开机自动启动代码

    几天前头儿要我实现程序能开机自动启动,搞好了,整理起来写下来. private void checkBox1_CheckedChanged(object sender, EventArgs e) { ...

  8. 用Django搭建个人博客—(1)

    业精于勤荒于嬉,形成于思毁于随. 本阶段的任务小记: 简单介绍一下Django的使用,创建项目和一个app 简单介绍一下Django的settings.py文件的相关配置 整合数据库到自己的博客系统中 ...

  9. 【读书笔记】【CLR via C#】【第一章】The CLR’s Execution Model

    内容提要 本章的目的是对.Net 框架的设计做一个总体的介绍,包括介绍框架中使用的一些技术.定义一些术语.同时会展示从源代码生成应用程序(或者一些包含了一些自定义类型的可以发布的组件),并且会解释程序 ...

  10. POJ 2513 Colored Sticks 字典树、并查集、欧拉通路

    Description You are given a bunch of wooden sticks. Each endpoint of each stick is colored with some ...