【动态规划09】hdu3853 LOOPS(期望dp)
来源:互联网 发布:中国软件企业排名 编辑:程序博客网 时间:2024/05/29 13:27
题目描述
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.
总而言之就是一个r*c的矩阵,每次移动的cost是2,每次可以向右向下或者不动给你三种情况的概率,求从
(1,1)到(r,c)的最小期望膜力。
很容易想到设f[i][j]表示从(i,j)到(r,c)所需要的膜力期望。
f[i][j]一共可以到达f[i+1][j],f[i][j+1]和f[i][j]。
易得到递推式f[i][j]=(2+f[i][j])*mp[i][j][0]+(2+f[i][j+1]*mp[i][j][1]+(2+f[i+1][j])*mp[i][j][2]
移向得到f[i][j]=
需要注意的是特殊判断分母不能为0
#include<bits/stdc++.h>#define fer(i,j,n) for(int i=j;i<=n;i++)#define far(i,j,n) for(int i=j;i>=n;i--)#define ll long longconst int maxn=1010;const int INF=1e9+7;using namespace std;/*----------------------------------------------------------------------------*/inline int read(){ char ls;int x=0,sng=1; for(;ls<'0'||ls>'9';ls=getchar())if(ls=='-')sng=-1; for(;ls>='0'&&ls<='9';ls=getchar())x=x*10+ls-'0'; return x*sng;}/*----------------------------------------------------------------------------*/double mp[maxn][maxn][3],f[maxn][maxn];int n,m;int main(){ while(scanf("%d%d",&n,&m)!=EOF) { fer(i,1,n) fer(j,1,m) fer(k,0,2) scanf("%lf",&mp[i][j][k]); f[n][m]=0; far(i,n,1) far(j,m,1) { if(i==n&&j==m)continue; if(mp[i][j][0]==1)continue; f[i][j]=(2+f[i][j+1]*mp[i][j][1]+f[i+1][j]*mp[i][j][2])/(1-mp[i][j][0]); } printf("%.3lf\n",f[1][1]); }}
阅读全文
0 0
- 【动态规划09】hdu3853 LOOPS(期望dp)
- 【期望DP】HDU3853 LOOPS
- HDU3853:LOOPS(概率dp & 期望)
- hdu3853 LOOPS 概率dp求期望
- HDU3853-LOOPS(概率DP求期望)
- hdu3853 LOOPS 【概率DP+期望问题】
- hdu3853[LOOPS] 继续浅尝期望概率DP
- [HDU3853]LOOPS简单期望
- LOOPS(hdu3853,概率DP入门)
- HDU3853:LOOPS(概率DP)
- HDU3853--LOOPS--概率DP
- HDU3853 LOOPS 概率DP
- HDU3853 LOOPS 概率DP
- [dp] hdu3853 loops
- hdu3853 LOOPS(概率dp)
- hdu3853(概率DP求期望)
- LOOPS(HDU3853)
- HDU 3853 LOOPS(期望DP)
- JAVA 缓存数组之----ByteArrayInputStream类详解
- Java中的异常
- Java程序设计编程题目
- 通过点击事件引用input[type=file]
- linux应用项目(一)数码相框(2)数码相框之字符编码与字符的点阵显示
- 【动态规划09】hdu3853 LOOPS(期望dp)
- $argv — 传递给脚本的参数数组
- mysql在表的某一位置增加一列、删除一列、修改列名
- 为什么JVM上没有C#语言?浅谈Type Erasure特性
- JS 数组去重(数组元素是对象的情况)
- 安卓新标准出台_告别乱弹窗_你的手机真会省电么?
- IPC基础概念
- [PolicyException: 无法获取所需的权限。]
- 【Android】【Other】Android 开发最佳实践