题意:

在一个r*c的网格中行走,在每个点分别有概率向右、向下或停止不动。每一步需要的时间为2,问从左上角走到右下角的期望时间。

SOL:

非常水一个DP...(先贴个代码挖个坑

code:

/*==========================================================================
# Last modified: 2016-01-20 23:08
# Filename: HDU3853.cpp
# Description:
==========================================================================*/
#define me AcrossTheSky
#include <cstdio>
#include <cmath>
#include <ctime>
#include <string>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm> #include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#define lowbit(x) (x)&(-x)
#define INF 1070000000
#define FOR(i,a,b) for((i)=(a);(i)<=(b);(i)++)
#define FORP(i,a,b) for (int i=(a);i<=(b);i++)
#define FORM(i,a,b) for (int i=(a);i>=(b);i--)
#define ls(a,b) (((a)+(b)) << 1)
#define rs(a,b) (((a)+(b)) >> 1)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
/*==================split line==================*/
struct P{
double on,r,d;
}prob[1050][1050];
double dp[1050][1050]; int main(){
int r,c;
while (scanf("%d%d",&r,&c)!=EOF){ memset(prob,0,sizeof(prob));
memset(dp,0,sizeof(dp));
for (int i=1;i<=r;i++)
for (int j=1;j<=c;j++) {
scanf("%lf%lf%lf",&prob[i][j].on,&prob[i][j].r,&prob[i][j].d);
//dp[i][j]=prob[i][j].on*2.0;
}
for (int i=r;i>=1;i--)
for (int j=c;j>=1;j--)
if (i==r && j==c) continue;
else if (prob[i][j].on-1==0) dp[i][j]=0;
else{
dp[i][j]=(dp[i+1][j]*prob[i][j].d+dp[i][j+1]*prob[i][j].r+2)/(1-prob[i][j].on);
}
for (int i=1;i<=r;i++){
for (int j=1;j<=c;j++) printf("%.3lf ",dp[i][j]);
cout << endl;
}
printf("%.3lf\n",dp[1][1]);
}
}

HDU 3853(期望DP)的更多相关文章

  1. HDU 3853 期望概率DP

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

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

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

  3. HDU 4405 期望DP

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

  4. hdu 3853 概率dp

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

  5. HDU 4035 期望dp

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

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

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

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

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

  8. 概率dp HDU 3853

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

  9. HDU 4405 Aeroplane chess 期望dp

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

随机推荐

  1. java常见异常集锦

    1. java.lang.nullpointerexception 这个异常大家肯定都经常遇到,异常的解释是"程序遇上了空指针",简单地说就是调用了未经初始化的对象或者是不存在的对 ...

  2. HDOJ 2955 Robberies (01背包)

    10397780 2014-03-26 00:13:51 Accepted 2955 46MS 480K 676 B C++ 泽泽 http://acm.hdu.edu.cn/showproblem. ...

  3. Solr5.3.1 SolrJ查询索引结果

    通过SolrJ获取Solr检索结果 1.通过SolrParams的方式提交查询参数 SolrClient solr = new HttpSolrClient("http://localhos ...

  4. msysgit ls 中文显示

    2013年10月17日 14:54:15 安装了新版的msysgit后,在其自带的 git bash 命令行下就可以输入中文汉字了 但是创建了中文名字命名的文件后,再用 ls 命令查询时会出现乱码的情 ...

  5. libavcodec/dxva2.h:40:5: error: unknown type name 'IDirectXVideoDecoder'

    gcc 4.9.2 编译 ffmpeg-git-1aeb88b 是出现如下错误 > FFmpeg fails to make with: > > CC libavcodec/dxva ...

  6. Java for LeetCode 072 Edit Distance【HARD】

    Given two words word1 and word2, find the minimum number of steps required to convert word1 to word2 ...

  7. Java for LeetCode 042 Trapping Rain Water

    Given n non-negative integers representing an elevation map where the width of each bar is 1, comput ...

  8. 将Excel文件.xls导入SQL Server 2005

    SQL2005 Microsoft SQL Server Management Studio Express管理器里,右键单击一个数据库,指向“任务”,再单击“导入数据”或“导出数据”中没有这个选项, ...

  9. [MAC] Mac OS X下快速复制文件路径的方法

    在windows上复制当前目录的路径有一个特别方便的方式,只需要用鼠标点击路径栏,它就会自动变成像”D:\Downloads\tmp”这样的路径,如果要复制文件路径,只需要将目录路径和文件名拼接起来即 ...

  10. HttpHandler简介

    新建的一般处理程序后缀为.ashx,一般会另外新建一个后缀为.ashx.cs的文件,其实所有的代码都写在.ashx.cs里面,只是微软帮我们做了一个傻瓜化的转换新建的一般处理程序,如:Text1,它就 ...