题意:

在一个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. Phpstorm常用设置

    Phpstorm更换主题和字体 1.File -- settings -- Editor -- Colors And Fonts: 2.在右侧窗口中选择Scheme name : 选择一个自己喜欢的主 ...

  2. ZeroMQ(java)中对IO的封装(StreamEngine)

    哎,各种各样杂七杂八的事情...好久没有看代码了,其实要搞明白一个与IO相关的框架,最好的办法就是把它的I/0的读写两个过程搞清楚...例如在netty中,如果能将eventLoop的运行原理搞清楚, ...

  3. Aptana插件安装到eclipse和myeclipse的详细过程

    刚开始学习Jquery,为了搭建好的环境是很重要的,所以我尝试了很多方式,下面之一. 一.要下载好Aptana 插件 官网: http://update1.aptana.org/studio/3.2/ ...

  4. 搭建自己的ngrok服务

    转载:http://tonybai.com/2015/03/14/selfhost-ngrok-service/ 在国内开发微信公众号.企业号以及做前端开发的朋友想必对ngrok都不陌生吧,就目前来看 ...

  5. ubuntu 12.04 server编译安装nginx

    tar -xvf zlib-1.2.8.tar.gz cd zlib-1.2.8 ./config make make install above is for zlib(refers http:// ...

  6. VMware Snapshot 工作原理

    VMware中的快照是对VMDK在某个时间点的“拷贝”,这个“拷贝”并不是对VMDK文件的复制,而是保持磁盘文件和系统内存在该时间点的状态,以便在出现故障后虚拟机能够恢复到该时间点.如果对某个虚拟机创 ...

  7. Bulls and Cows

    You are playing the following Bulls and Cows game with your friend: You write down a number and ask ...

  8. hdu3555

    基本的数位dp #include <cstdio> #include <cstring> using namespace std; #define D(x) x ; long ...

  9. Java for LeetCode 140 Word Break II

    Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each ...

  10. 6.django笔记之orm

    作者:刘耀 一.Django-orm 关系对象映射(Object Relational Mapping,简称ORM). 2.在django里 我们写的类表示数据库的表 如果根据这个类创建的对象是数据库 ...