LOOPS

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

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
 
      f[i][j]表示位于(i,j)距离目标的期望魔力值,可是对于朴素点如果p1=1的话那显然期望就是inf了因为会陷入死循环,特判一下改成0就过了。
    

 #include<iostream>
#include<cstring>
#include<queue>
#include<cstdio>
#include<stack>
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<time.h>
#include<algorithm>
using namespace std;
#define mp make_pair
#define pb push_back
#define debug puts("debug")
#define LL long long
#define pii pair<int,int>
#define eps 1e-10 double f[][];
double p[][][];
int main()
{
int n,m,i,j,k,t;
while(scanf("%d%d",&n,&m)==){
memset(f,,sizeof(f));
for(i=;i<=n;++i){
for(j=;j<=m;++j){
for(k=;k<;++k)
scanf("%lf",&p[i][j][k]);
}
}
f[n][m]=;
for(i=n;i>=;--i){
for(j=m;j>=;--j){
if(i==n&&j==m) continue;
double p1=p[i][j][],
p2=p[i][j][],
p3=p[i][j][];
if(fabs(p1-)<=eps) {
f[i][j]=;
continue;
}
f[i][j]=(p2*f[i][j+]+p3*f[i+][j]+)/((double)-p1);
}
}
printf("%.3f\n",f[][]);
}
return ;
}

HDU-3853-期望/dp/坑的更多相关文章

  1. HDU 3853(期望DP)

    题意: 在一个r*c的网格中行走,在每个点分别有概率向右.向下或停止不动.每一步需要的时间为2,问从左上角走到右下角的期望时间. SOL: 非常水一个DP...(先贴个代码挖个坑 code: /*== ...

  2. HDU 3853 期望概率DP

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

  3. poj 2096 , zoj 3329 , hdu 4035 —— 期望DP

    题目:http://poj.org/problem?id=2096 题目好长...意思就是每次出现 x 和 y,问期望几次 x 集齐 n 种,y 集齐 s 种: 所以设 f[i][j] 表示已经有几种 ...

  4. HDU 4405 期望DP

    期望DP算是第一题吧...虽然巨水但把思路理理清楚总是好的.. 题意:在一个1×n的格子上掷色子,从0点出发,掷了多少前进几步,同时有些格点直接相连,即若a,b相连,当落到a点时直接飞向b点.求走到n ...

  5. hdu 3853 概率dp

    题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...

  6. HDU 4035 期望dp

    这道题站在每个位置上都会有三种状态 死亡回到起点:k[i] 找到出口结束 e[i] 原地不动 p[i] k[i]+e[i]+p[i] =1; 因为只给了n-1条路把所有都连接在一起,那么我们可以自然的 ...

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

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

  8. HDU 3853 向下向右找出口问题-期望dp

    题意:初始状态在(1,1)的位置.目标是走到(n,n).每次仅仅能向下向右或者不移动.已知在每一个格子时这三种情况的概率,每移动一步消耗2的魔力,求走到终点的使用的魔力的期望. 分析:简单的期望dp, ...

  9. 概率dp HDU 3853

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

  10. HDU 4405 Aeroplane chess 期望dp

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 Aeroplane chess Time Limit: 2000/1000 MS (Java/ ...

随机推荐

  1. JAVAWEB Filter使用

    Filter学习 1Filter是什么:是过滤器简称 2Filter有什么作用:在filter中可以得到代表用户请求和响应的request.response对象,因此在编程中可以使用Decorator ...

  2. Drainage Ditches---hdu1532(最大流)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1532 题意: 每次下雨的时候,农场主John的农场里就会形成一个池塘,这样就会淹没其中一小块土地,在这 ...

  3. mysql备份的4种方式

    mysql备份的4种方式 转载自:https://www.cnblogs.com/SQL888/p/5751631.html 总结: 备份方法 备份速度 恢复速度 便捷性 功能 一般用于 cp 快 快 ...

  4. 002-线程实现方式【thread、runnable、callale、thread和runnable对比】

    一.概述 1.实现方式 在java中对于多线程实现一定要有一个线程的主类,而这个线程的主类往往是需要操作一些资源,但是对于多线程主类的实现是: 继承Thread父类 从java的Thread类继承实现 ...

  5. java模拟网页http-url访问

    package com.iflytek; import java.io.InputStream; import java.net.HttpURLConnection; import java.net. ...

  6. CSLA.Net学习(2)

    采用CSLA.net 2.1.4.0版本的书写方式: using System; using System.ComponentModel; using Csla.Validation; using S ...

  7. CentOS7.5基础优化与常用配置

    目录 最小化全新安装CentOS7基础优化 配置yum源 安装常用软件 关闭防火墙 关闭SELinux 优化ulimit 历史命令记录改为1万条 把命令提示符改为绿色 添加vim配置文件 添加一个普通 ...

  8. java基础知识面试题(1-40)

    1.面向对象的特征有哪些方面?答:面向对象的特征主要有以下几个方面:- 抽象:抽象是将一类对象的共同特征总结出来构造类的过程,包括数据抽象和行为抽象两方面.抽象只关注对象有哪些属性和行为,并不关注这些 ...

  9. redis入门学习记录(一)

    1.linux在线下载Redis ,官网地址:https://redis.io/download目前,最新的Redist版本为redis-5.0.0,使用wget下载 进入/usr/local/src ...

  10. Git冲突:commit your changes or stash them before you can merge. 解决办法

    用git pull来更新代码的时候,遇到了下面的问题: 1 2 3 4 error: Your local changes to the following files would be overwr ...