HDU 3853-loop(概率dp入门)

题意:

r*c个方格,从(1,1)开始在每个方格可释放魔法(消耗能量2)以知,释放魔法后可能在原地、可能到达相邻的下面格子或右面格子,给出三者的概率

求要到达(R,C)格子,要消耗能量的期望值。

分析:

状态好确定,dp[i][j]表示(i,j)到达(r,c)还需要的能量值,则dp[r][c]=0,dp[1][1]就是答案

dp[i][j]=dp[i][j]*p[i][j][0]+dp[i][j+1]*p[i][j][1]+dp[i+1][j]*p[i][j][2]+2.0,再移项即可;

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <complex>
#include <cassert>
#include <utility>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
typedef pair<int,int> PII;
typedef long long ll;
#define lson l,m,rt<<1
#define pi acos(-1.0)
#define rson m+1,r,rt<<11
#define All 1,N,1
#define read freopen("in.txt", "r", stdin)
const ll  INFll = 0x3f3f3f3f3f3f3f3fLL;
const int INF= 0x7ffffff;
const int mod =  1000000007;
double dp[1010][1010],p[1010][1010][4];
int r,c;
void solve(){
    memset(dp,0,sizeof(dp));
    for(int i=r;i>=1;--i)
        for(int j=c;j>=1;--j)
    {
        if(i==r&&j==c)continue;
        if(p[i][j][0]==1.000)continue;//表示无路可走,只能留在原地
        dp[i][j]=dp[i][j+1]*p[i][j][1]+dp[i+1][j]*p[i][j][2]+2.0;
        dp[i][j]/=(1.0-p[i][j][0]);
    }
    printf("%.3lf\n",dp[1][1]);
}
int main()
{
    while(~scanf("%d%d",&r,&c)){
        for(int i=1;i<=r;++i)
            for(int j=1;j<=c;++j)
            for(int k=0;k<3;++k)
            scanf("%lf",&p[i][j][k]);
        solve();
    }
return 0;
}
时间: 2024-10-12 05:59:01

HDU 3853-loop(概率dp入门)的相关文章

hdu 5001 walk 概率dp入门题

Description I used to think I could be anything, but now I know that I couldn't do anything. So I started traveling. The nation looks like a connected bidirectional graph, and I am randomly walking on it. It means when I am at node i, I will travel t

HDU 3853 LOOPS (概率dp)

LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 2931    Accepted Submission(s): 1209 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help

HDU 3853 期望概率DP

期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] ,  右移:[x][y]->[x][y+1]=p[x][y][1];  左移:[x][y]->[x+1][y]=p[x][y][2]; 问最后走到[r,c]的期望 dp[i][j]为从[i][j]点走到[r][c]的期望 有方程: dp[i][j]=    (dp[i][j]+2)*p[i][j][0]  +   (dp

LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)

题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1.设变量:(注意:设置变量时,要能够使整个求解过程可以分为多个阶段.) 2.分析阶段决策,并写出决策函数.(也就是能体现前阶段决策后阶段关系的函数) 3.写出指标函数.(也是就是我们得出解的函数.) 先第一步:设置变量,我们分析这个题的是从(1,1)到(r, c)那么什么能体现"阶段"这个

HDU 3853 LOOPS 概率dp(水

水水过~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> #include <cmath> template <class T> inline bool rd(T &ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-'&&(c&l

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

题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Total Submission(s): 2630    Accepted Submission(s): 1081 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to h

hdu4405概率dp入门

Aeroplane chess Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1122    Accepted Submission(s): 762 Problem Description Hzz loves aeroplane chess very much. The chess map contains N+1 grids lab

hdu3853之概率dp入门

LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 1651    Accepted Submission(s): 653 Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help h

hdu 4870 Rating(概率DP&amp;高数消元)

Rating Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 714    Accepted Submission(s): 452 Special Judge Problem Description A little girl loves programming competition very much. Recently, she