LOOPS

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others) Total Submission(s): 2552    Accepted Submission(s): 1041

Problem Description
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.
 
Input
The first line contains two integers R and C (2 <= R, C <= 1000).
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
A real number at 3 decimal places (round to), representing the expect magic power Homura need to escape from the LOOPS.
 
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
 
Source
 
题意:有一个r*c的格子,从格子(1,1)出发,可以保持三种姿势,留在原地,向右一步,向下一步,且给出相应的概率,每走一步消耗2的魔法值,问最后到达(r,c)平均需要多少魔法值、
 
题解:
    我们知道概率的  E(i)=p1+p2+p3......+pn;
    对于E(ax+bk)=a*Ex+b*Ek;
我们不妨从(r,c)出发:
        首先要明确的是: 在没有到达(r,c)之前,是不能停留的。所以
         dp[1][1]=dp[1][2]*mat[1][1][3]+dp[2][1]*mat[1][1][2];
         dp[1][1]=dp[1][1]/(1-map[1][1][0])   //除去停下来的其他概率,得到期望    
依次这样推:
        dp[i][j]=dp[i][j+1]*mat[i][j][3]+dp[i+1][j]*mat[i][j][2];

         dp[i][j]=dp[i][j]/(1-map[i][j][0])   //除去停下来的其他概率,得到期望  
但是由于这样从(1,1)推断,会出现将不收敛问题;
代码:
//#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)的更多相关文章

  1. HDU 4599 概率DP

    先推出F(n)的公式: 设dp[i]为已经投出连续i个相同的点数平均还要都多少次才能到达目标状态. 则有递推式dp[i] = 1/6*(1+dp[i+1]) + 5/6*(1+dp[1]).考虑当前这 ...

  2. HDU 5001 概率DP || 记忆化搜索

    2014 ACM/ICPC Asia Regional Anshan Online 给N个点,M条边组成的图,每一步能够从一个点走到相邻任一点,概率同样,问D步后没走到过每一个点的概率 概率DP  測 ...

  3. hdu 3853 概率dp

    题意:在一个R*C的迷宫里,一个人在最左上角,出口在右下角,在每个格子上,该人有几率向下,向右或者不动,求到出口的期望 现在对概率dp有了更清楚的认识了 设dp[i][j]表示(i,j)到(R,C)需 ...

  4. HDU 4815 概率dp,背包

    Little Tiger vs. Deep Monkey Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K ( ...

  5. hdu 4050(概率dp)

    算是挺简单的一道概率dp了,如果做了前面的聪聪于可可的话,这题不需要什么预处理,直接概率dp就行了... #include <stdio.h> #include <stdlib.h& ...

  6. HDU 4405 (概率DP)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=4405 题目大意:飞行棋.如果格子不是飞行点,扔骰子前进.否则直接飞到目标点.每个格子是唯一的飞行起点 ...

  7. hdu 4336 概率dp + 状压

    hdu 4336 小吃包装袋里面有随机赠送一些有趣的卡片,如今你想收集齐 N 张卡片.每张卡片在食品包装袋里出现的概率是p[i] ( Σp[i] <= 1 ), 问你收集全部卡片所需购买的食品数 ...

  8. hdu 4576(概率dp+滚动数组)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4576 思路:由于每次从某一位置到达另一位置的概率为0.5,因此我们用dp[i][j]表示第i次操作落在 ...

  9. hdu 5001 概率DP 图上的DP

    http://acm.hdu.edu.cn/showproblem.php?pid=5001 当时一看是图上的就跪了 不敢写,也没退出来DP方程 感觉区域赛的题  一则有一个点难以想到 二则就是编码有 ...

随机推荐

  1. UVA 11584 一 Partitioning by Palindromes

    Partitioning by Palindromes Time Limit:1000MS     Memory Limit:0KB     64bit IO Format:%lld & %l ...

  2. 数独Sudoku

    数独(すうどく,Sūdoku),是源自18世纪瑞士发明,流传到美国,再由日本发扬光大的一种数学游戏.是一种运用纸.笔进行演算的逻辑游戏.玩家需要根据9×9盘面上的已知数字,推理出所有剩余空格的数字,并 ...

  3. 通过NuGet获取sqlite对应的.net的dll

    https://www.nuget.org/packages/System.Data.SQLite/ 直接在Package Manager Console中执行命令,会自动安装依赖项的 Install ...

  4. web后门top

    看到了一个博客  觉得关键点很有用 1)出现频率最高的DDoS后门文件名 abc.php, xl.php, Xml.php, dedetag.class.php, counti.php, plase. ...

  5. [SAP ABAP开发技术总结]权限对象检查

    声明:原创作品,转载时请注明文章来自SAP师太技术博客( 博/客/园www.cnblogs.com):www.cnblogs.com/jiangzhengjun,并以超链接形式标明文章原始出处,否则将 ...

  6. CA*Layer(CAShapeLayer--CATextLayer)

    CAShapeLayer CAShapeLayer是一个通过矢量图形而不是bitmap来绘制的图层子类.你指定诸如颜色和线宽等属性,用CGPath来定义想要绘制的图 形,最后CAShapeLayer就 ...

  7. Linux红帽认证----I Want

    仅此设定一个目标,此证一定搞到手!!!

  8. poj 2187 Beauty Contest (凸包暴力求最远点对+旋转卡壳)

    链接:http://poj.org/problem?id=2187 Description Bessie, Farmer John's prize cow, has just won first pl ...

  9. nyoj325 zb的生日(DFS)

    zb的生日 时间限制:3000 ms  |  内存限制:65535 KB 难度:2   描述 今天是阴历七月初五,acm队员zb的生日.zb正在和C小加.never在武汉集训.他想给这两位兄弟买点什么 ...

  10. jQuery 中$(this).parent().parent().remove()无效。

    在写文章系统的删除功能.需要删除一行数据.在删除的页面,需要jQuery 删除一hang. 局部刷新数据. $(".del").click(function(){ var id = ...