HDU 3853 LOOPS 概率DP入门
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 8453 Accepted Submission(s): 3397
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.
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
0.00 0.50 0.50 0.50 0.00 0.50
0.50 0.50 0.00 1.00 0.00 0.00
#include<bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define ll long long
#define inf 1000000000
#define maxn 1005
#define maxm 100005
#define eps 1e-10
#define for0(i,n) for(int i=1;i<=(n);++i)
#define for1(i,n) for(int i=1;i<=(n);++i)
#define for2(i,x,y) for(int i=(x);i<=(y);++i)
#define for3(i,x,y) for(int i=(x);i>=(y);--i)
#define mod 1000000007
inline int read()
{
int x=,f=;char ch=getchar();
while(ch<''||ch>'') {if(ch=='-') f=-;ch=getchar();}
while(ch>=''&&ch<='') {x=*x+ch-'';ch=getchar();}
return x*f;
}
double dp[maxn][maxn];
double p1[maxn][maxn],p2[maxn][maxn],p3[maxn][maxn];
int main()
{
int r,c;
while(~scanf("%d%d",&r,&c))
{
for(int i=;i<=r;++i)
for(int j=;j<=c;++j)
scanf("%lf%lf%lf",&p1[i][j],&p2[i][j],&p3[i][j]);
mem(dp,);
for(int i=r;i>=;--i)
for(int j=c;j>=;--j)
{
if(i==r&&j==c) continue;
if(p1[i][j]==1.00) continue;
dp[i][j]=(p2[i][j]*dp[i][j+]+p3[i][j]*dp[i+][j]+)/(-p1[i][j]);
}
printf("%.3lf\n",dp[][]);
}
}
HDU 3853 LOOPS 概率DP入门的更多相关文章
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- HDU 3853 LOOPS 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...
- HDU 3853 期望概率DP
期望概率DP简单题 从[1,1]点走到[r,c]点,每走一步的代价为2 给出每一个点走相邻位置的概率,共3中方向,不动: [x,y]->[x][y]=p[x][y][0] , 右移:[x][y ...
- LOOPS HDU - 3853 (概率dp):(希望通过该文章梳理自己的式子推导)
题意:就是让你从(1,1)走到(r, c)而且每走一格要花2的能量,有三种走法:1,停住.2,向下走一格.3,向右走一格.问在一个网格中所花的期望值. 首先:先把推导动态规划的基本步骤给出来. · 1 ...
- HDU 3853 LOOP (概率DP求期望)
D - LOOPS Time Limit:5000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Submit St ...
- HDU 3853-loop(概率dp入门)
题意: r*c个方格,从(1,1)开始在每个方格可释放魔法(消耗能量2)以知,释放魔法后可能在原地.可能到达相邻的下面格子或右面格子,给出三者的概率 求要到达(R,C)格子,要消耗能量的期望值. 分析 ...
- HDU 3853 LOOPS 可能性dp(水
在拐~ #include <stdio.h> #include <cstring> #include <iostream> #include <map> ...
- HDU 3853LOOPS(简单概率DP)
HDU 3853 LOOPS 题目大意是说人现在在1,1,需要走到N,N,每次有p1的可能在元位置不变,p2的可能走到右边一格,有p3的可能走到下面一格,问从起点走到终点的期望值 这是弱菜做的第 ...
随机推荐
- 1048: [HAOI2007]分割矩阵
Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1184 Solved: 863[Submit][Status][Discuss] Descripti ...
- python用requests请求,报SSL:CERTIFICATE_VERIFY_FAILED错误。
response = requests.request("GET", url, headers=headers, params=querystring, verify=False) ...
- shell脚本中case的用法
shell脚本中case选择语句可以结合read指令实现比较好的交互应答操作,case接收到read指令传入的一个或多个参数,然后case根据参数做选择操作. case的语法如下 case $char ...
- Date.prototype.Format---对Date的扩展
// 对Date的扩展,将 Date 转化为指定格式的String // 月(M).日(d).小时(h).分(m).秒(s).季度(q) 可以用 1-2 个占位符, // 年(y)可以用 1-4 个占 ...
- 【Linux】linux 机器之间 zssh, rz, sz互相传输
服务器端安装lrzsz: sudo yum install lrzsz 本地客户端安装lrzsz: brew install lrzsz 本地客户端安装zssh: brew install zssh ...
- Vue插槽
插槽内容 Vue实现一套内容分发的API, 这套API基于当前的web组件规范草案,将元素作为承载分发内容的出口. <navigation-link url="/profile&quo ...
- PHP递归排序怎么实现的?
递归算法对于任何一个编程人员来说,应该都不陌生.因为递归这个概念,无论是在PHP语言还是Java等其他编程语言中,都是大多数算法的灵魂. 对于PHP新手来说,递归算法的实现原理可能不容易理解.但是 ...
- JZOJ 5775. 【NOIP2008模拟】农夫约的假期
5775. [NOIP2008模拟]农夫约的假期 (File IO): input:shuru.in output:shuru.out Time Limits: 1000 ms Memory Lim ...
- 解决cmd目录下pip命令不存在的问题
解决cmd目录下pip命令不存在的问题 注:pip.exe程序在Python安装目录下的scripts中1.在cmd命令中输入: 先输入:python -m ensurepip 再输入:python ...
- day25-python之继承组合
1.上节回顾 class School: x=1 def __init__(self,name,addr,type): self.Name=name self.Addr=addr self.Type= ...