概率dp HDU 3853
Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d
& %I64u
cid=60444#status//H/0" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)">Status
id=20651" class="ui-button ui-widget ui-state-default ui-corner-all ui-button-text-only" style="display:inline-block; position:relative; padding:0px; margin-right:0.1em; vertical-align:middle; overflow:visible; text-decoration:none; font-family:Verdana,Arial,sans-serif; font-size:1em; border:1px solid rgb(211,211,211); color:rgb(85,85,85)">Practice
HDU3853
System Crawler (2014-10-22)
Description
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 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
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
题意:一个R*C的矩阵,起点在(1,1),终点在(R。C),告诉你在每一个点在原地。向右,向下的概率,每次花费2个能量去移动(呆在原地也可)。求到达终点的能量花费期望。
本题须要注意题目说期望小于1e6,那么呆在那个点的概率为1的点肯定从起点出发不可达的点。
否则期望会无穷大。
dp[i][j]表示从(i,j)到(r,c)所须要的期望能量。
/*************************************************************************
> File Name: t.cpp
> Author: acvcla
> Mail: acvcla@gmail.com
> Created Time: 2014年10月21日 星期二 21时33分55秒
************************************************************************/
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<vector>
#include<cstring>
#include<map>
#include<queue>
#include<stack>
#include<string>
#include<cstdlib>
#include<ctime>
#include<set>
#include<math.h>
using namespace std;
typedef long long LL;
const int maxn = 1e3 + 10;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define pb push_back
double dp[maxn][maxn];
int r,c;
double Div(int a,int b){
return double(a)/b;
}
struct p
{
double p1,p2,p3;
}P[maxn][maxn];
int main(int argc, char const *argv[])
{
while(~scanf("%d%d",&r,&c)){
for(int i=1;i<=r;i++){
for(int j=1;j<=c;j++){
scanf("%lf%lf%lf",&P[i][j].p1,&P[i][j].p2,&P[i][j].p3);
}
}
//memset(dp,0,sizeof dp);
dp[r][c]=0;
for(int i=r;i>=1;i--)
for(int j=c;j>=1;j--){
dp[i][j]=0;
if(i==r&&j==c||P[i][j].p1==1)continue;
dp[i][j]=(dp[i+1][j]*P[i][j].p3+dp[i][j+1]*P[i][j].p2+2)/(1-P[i][j].p1);
}
printf("%.3f\n",dp[1][1]);
}
return 0;
}
概率dp HDU 3853的更多相关文章
- 概率DP hdu 3366 .
题意:一个人被困在一个城堡里,面前有n条路,他自己有m百万元,选择每一条路都有p概率通过,q概率遇到士兵,1-p-q概率道路不通:遇到士兵的话需要上交1百万,如果不够钱,则被杀死,问的是最优情况下多少 ...
- 概率dp HDU 4405
Aeroplane chess Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- [概率dp] hdu 5378 Leader in Tree Land
题意: 给你一颗以1位根节点的树.我们定义对于每一个子树,节点权值最大的权值记为这个子树的权值,为你将1~n放到这个树里 满足最大权值仅仅有k个的组合数是多少. 思路: 我们能够知道以每一个节点为子树 ...
- 概率DP HDU 4586 play the dice
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4586 解题思路: 只考虑第一次,获得的金币的平均值为sum/n.sum为所有色子的面的金币值相加. ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- HDU 3853 期望概率DP
期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] , 右移:[x][y ...
- hdu 3853 概率dp
题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...
- HDU 3853 LOOPS 概率DP入门
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
随机推荐
- 3ds Max灯光教程之卧室灯光布局实例
对于设计师来说要做好一张好的作品效果图包括很多比如:“造型.色彩搭配.灯光气氛.构图角度等等,上次给大家详细的分析了下产品渲染中摄像机的构图及原理.本期教程来跟大家讨论一下max场景灯光布局问题.以卧 ...
- 关于Python的装饰器
false 7.8 磅 0 2 false false false EN-US ZH-CN X-NONE /* Style Definitions */ table.MsoNormalTable {m ...
- CodeForces-920E Connected Components? 广度搜索 双向链表 判断联通 大量重复节点的删除
题目链接:https://cn.vjudge.net/problem/CodeForces-920E 题意 给一个补图,问各个联通块有几个元素,升序排列 注意maxn=2e5, maxm=2e10 思 ...
- redis搭建与安装2
第一步redis安装:1.首先确认下载包为64位的还是32位的2.下载http://code.google.com/p/servicestack/downloads3.解压下载包得到以下文件:cygw ...
- oracle和mysql的分页
如果我们是通过JDBC的方式访问数据库,那么就有必要根据数据库类型采取不同的SQL分页语句,对于MySql数据库,我们可以采用limit语句进行分页,对于Oracle数据库,我们可以采用rownum的 ...
- sort排序到底怎么排序
sort()方法 sort() 方法在适当的位置对数组的元素进行排序,并返回数组. <!DOCTYPE html> <html> <head> <meta c ...
- Failed to initialize connector [Connector[HTTP/1.1-443]]
Failed to initialize connector [Connector[HTTP/1.1-443]] 出现如上错误时,是因为443端口被占用, 所以tomcat的https协议无法使用, ...
- HDU 1026 Ignatius and the Princess I(BFS+记录路径)
Ignatius and the Princess I Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- 作为一名Android APP开发者的自我总结
每当接近年尾,最痛苦的工作无疑是写年终总结,写总结的同时不禁感叹这一年过得不容易阿.突然想起这一年也是自己开发Android APP的第一年,于是觉得应该给自己的APP来一个年终总结. 一.开发方面严 ...
- LeetCode 232: Implement Queue using Stacks
Implement the following operations of a queue using stacks. push(x) -- Push element x to the back of ...