hdu 3853LOOPS (概率DP)
LOOPS
Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 2552 Accepted Submission(s): 1041
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.50 0.50 0.00 1.00 0.00 0.00
//#define LOCAL
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define maxn 1001
double dp[maxn][maxn];
double map[maxn][maxn][]; int main()
{
int rr,cc;
#ifdef LOCAL
freopen("test.in","r",stdin);
#endif while(scanf("%d%d",&rr,&cc)!=EOF)
{
for(int i=;i<=rr;i++)
for(int j=;j<=cc;j++)
scanf("%lf%lf%lf",&map[i][j][],&map[i][j][],&map[i][j][]);
memset(dp,,sizeof(dp));
for(int i=rr;i>;i--)
for(int j=cc;j>;j--){
if(i==rr&&j==cc)
continue; //(rr,cc)这个点是出口不需要在走了,停在原地 if(map[i][j][]!=1.0) //如果没有到终点停下来的话,题目就会误解!
{
dp[i][j]=dp[i][j]*map[i][j][]+dp[i+][j]*map[i][j][]+dp[i][j+]*map[i][j][]+;
dp[i][j]/=(1.0-map[i][j][]);
} }
printf("%.3lf\n",dp[][]);
} return ;
}
hdu 3853LOOPS (概率DP)的更多相关文章
- HDU 4599 概率DP
先推出F(n)的公式: 设dp[i]为已经投出连续i个相同的点数平均还要都多少次才能到达目标状态. 则有递推式dp[i] = 1/6*(1+dp[i+1]) + 5/6*(1+dp[1]).考虑当前这 ...
- HDU 5001 概率DP || 记忆化搜索
2014 ACM/ICPC Asia Regional Anshan Online 给N个点,M条边组成的图,每一步能够从一个点走到相邻任一点,概率同样,问D步后没走到过每一个点的概率 概率DP 測 ...
- hdu 3853 概率dp
题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...
- HDU 4815 概率dp,背包
Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K ( ...
- hdu 4050(概率dp)
算是挺简单的一道概率dp了,如果做了前面的聪聪于可可的话,这题不需要什么预处理,直接概率dp就行了... #include <stdio.h> #include <stdlib.h& ...
- HDU 4405 (概率DP)
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 题目大意:飞行棋.如果格子不是飞行点,扔骰子前进.否则直接飞到目标点.每个格子是唯一的飞行起点 ...
- hdu 4336 概率dp + 状压
hdu 4336 小吃包装袋里面有随机赠送一些有趣的卡片,如今你想收集齐 N 张卡片.每张卡片在食品包装袋里出现的概率是p[i] ( Σp[i] <= 1 ), 问你收集全部卡片所需购买的食品数 ...
- hdu 4576(概率dp+滚动数组)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 思路:由于每次从某一位置到达另一位置的概率为0.5,因此我们用dp[i][j]表示第i次操作落在 ...
- hdu 5001 概率DP 图上的DP
http://acm.hdu.edu.cn/showproblem.php?pid=5001 当时一看是图上的就跪了 不敢写,也没退出来DP方程 感觉区域赛的题 一则有一个点难以想到 二则就是编码有 ...
随机推荐
- Eclipse中没有andriod问题解决方法
按照网上教程<andriod+环境搭建_图文版>进行安装android,结果,在eclipse中window->preference下找不到"Android"选项 ...
- CSS选择器、优先级与匹配原理(转)
CSS选择器.优先级与匹配原理 导航 为了分析Bootstrap源码,所以的先把CSS选择器相关的东东给巩固好 废话就不多说了 CSS 2.1 selectors, Part 1 计算指定选择器的优先 ...
- [UVa1213]Sum of Different Primes(递推,01背包)
题目链接:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem ...
- java web开发必备知识
从各种招聘网站的要求上筛选出了一些java开发的一些基本的要求,对照自身看看有哪些缺陷. java基础 既然是java web开发,java SE肯定要学好了. 多线程,IO,集合等,对队列,缓存,消 ...
- poj 2007 Scrambled Polygon(极角排序)
http://poj.org/problem?id=2007 Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 6701 A ...
- poj 1556 (Dijkstra + Geometry 线段相交)
链接:http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS Memory Limit: 10000K Total Submissi ...
- 发布《Linux工具快速教程》
发布<Linux工具快速教程> 阶段性的完成了这本书开源书籍,发布出来给有需要的朋友,同时也欢迎更多的朋友加入进来,完善这本书: 本书Github地址:https://github.com ...
- ZOJ-2366 Weird Dissimilarity 动态规划+贪心
题意:现给定一个字符集中一共Z个元素的环境,给出一个Z*Z的数组,表示从i到j之间的距离.给定两组字符串,分别问包含着两个字符串(给定的字符串为所求字符串的子序列不是子串)对应位的距离和值最小为多少? ...
- eclispse 中集成多个tomcat
1.背景 在本地需要运行两个项目进行测试时,需要同时启动两个服务器,所以集成多个Tomcat到eclipse就成为一个必要的知识点. 2.准备知识 2.1 因为同时在一台主机上运行,所以多个服务器共用 ...
- php使用cURL实现Get和Post请求的方法
1.cURL介绍 cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL 的一些高级特性 ...