HDOJ 3853 LOOPS
水概率DP。。。。
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)
Total Submission(s): 1359 Accepted Submission(s): 552
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 <iostream>
#include <cstdio>
#include <cstring>
#include <cmath> using namespace std; double dp[][];
struct ppp
{
double stay,right,down;
}p[][]; const double eps=1e-; int r,c; int main()
{
while(scanf("%d%d",&r,&c)!=EOF)
{
memset(dp,,sizeof(dp));
for(int i=;i<=r;i++) for(int j=;j<=c;j++)
scanf("%lf%lf%lf",&p[i][j].stay,&p[i][j].right,&p[i][j].down);
for(int i=r;i>=;i--)
{
for(int j=c;j>=;j--)
{
if(i==r&&j==c) continue;
if(fabs(p[i][j].stay-.)<=eps) continue;
dp[i][j]=./(-p[i][j].stay)*(dp[i+][j]*p[i][j].down+dp[i][j+]*p[i][j].right+.);
}
}
printf("%.3lf\n",dp[][]);
}
return ;
}
HDOJ 3853 LOOPS的更多相关文章
- HDU 3853 LOOPS 期望dp
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=3853 LOOPS Time Limit: 15000/5000 MS (Java/Others)Me ...
- 【HDU】3853 LOOPS
http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意:n×m的格子,起始在(1,1),要求走到(n,m),在每一格(i,j)有三种走法,其中p[i,j,0 ...
- hdu 3853 LOOPS(概率 dp 期望)
Problem Description Akemi Homura is a Mahou Shoujo (Puella Magi/Magical Girl). Homura wants to help ...
- HDU 3853 LOOPS 概率DP入门
LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Total Sub ...
- HDU 3853 LOOPS:期望dp【网格型】
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3853 题意: 有一个n*m的网格. 给出在每个格子时:留在原地.向右走一格,向下走一格的概率. 每走一 ...
- hdu 3853 LOOPS (概率dp 逆推求期望)
题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others)Tota ...
- hdu 3853 LOOPS(基础DP求期望)
题目大意 有一个人被困在一个 R*C(2<=R,C<=1000) 的迷宫中,起初他在 (1,1) 这个点,迷宫的出口是 (R,C).在迷宫的每一个格子中,他能花费 2 个魔法值开启传送通道 ...
- hdu 3853 LOOPS 概率DP
简单的概率DP入门题 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include ...
- HDU 3853 LOOPS
题意:对于每一格,都可以往右走,原地不走,往下走,概率分别为a[i],b[i],c[i](每一个格子与其他格子的概率不一定相同).在R*C的棋盘上(输入数据保证不会走出棋盘),求从(0, 0)走到(R ...
随机推荐
- js调用刷新
_self.fireEvent('refresh');
- SLF4J的好处
原来我们使用log4j去打印日志,如果我们要更改日志记录器,比如用comms-Logging,那我们在代码里面还要改每个类的引用包,但是如果用slf4j的话只要在配置的时候改下,代码完全用slf4j的 ...
- TypeScript Class(类)
传统的JavaScript注重用函数和基于原型的继承来创建可复用的组件,但这可能让用习惯面对对象方式的程序员感到棘手,因为他们的继承和创建对象都是由类而来的.从JavaScript的下一个版本,ECM ...
- Python翻转字符串或者列表的方式
1. reversed class reversed(object) | reversed(sequence) -> reverse iterator over values of the se ...
- Android配置文件,所有权限
访问登记属性 android.permission.ACCESS_CHECKIN_PROPERTIES ,读取或写入登记check-in数据库属性表的权限 获取错略位置 android.permiss ...
- 【Alpha阶段】第十次Scrum例会
会议信息 挺过编译ddl,开始Alpha阶段最后的调试 时间:2016.11.08 21:30 时长:25min 地点:大运村1公寓5楼 类型:日常会议 NXT:2016.11.10 21:30 个人 ...
- CSS--值和单位
等价颜色表 什么叫Web安全色 所谓的“web安全”颜色是指在256色计算机系统上总能避免抖动的颜色. Web安全颜色可以表示为RGB值为20%和51(相应的十六进制值为33)的倍数. 如果使用RGB ...
- Yocto开发笔记之《Makefile编写》(QQ交流群:519230208)
开了一个交流群,欢迎爱好者和开发者一起交流,转载请注明出处. QQ群:519230208,为避免广告骚扰,申请时请注明 “开发者” 字样 =============================== ...
- 多态 oc c++ 与oc category
多态是函数调用的动态绑定技术: c++动态绑定依赖于this指针与虚函数表. 虚函数表的排序规则: 1)虚函数按照其声明顺序放于表中. 2)父类的虚函数在子类的虚函数前面. 3)如果子类重写了父类的虚 ...
- linux安装pip
1.先说一下什么是pippip 是"A tool for installing and managing Python packages.",也就是说pip是python的软件安装 ...