LOOPS

Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)

Total Submission(s): 4636    Accepted Submission(s): 1862

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
 
—————————————————————————————————————————————————————————————————————————————
本题为概率dp的入门题,题目的意思是计算从(1,1)到(r,c)的期望。
题目给出了个r*c的矩阵,在每个点,你都可能不动或向下或向右移动,概率分别为p1,p2,p3,每步消耗2。
我们设dp[i][j]为从(i,j)到(r,c)的期望;
首先很容易知道dp[r][c]=0;
其他各个点为dp[i][j]=2+p1[i]j[]*dp[i][j]p2[i][j]*dp[i][j+1]+p3[i][j]*dp[i+1][j])
移项后即dp[i][j]=(2+p2[i][j]*dp[i][j+1]+p3[i][j]*dp[i+1][j])/(1-p1[i][j]);




代码如下:




#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
double p1[1005][1005],p2[1005][1005],p3[1005][1005],dp[1005][1005];
int main()
{
int r,c;
while(~scanf("%d%d",&r,&c))
{
for(int i=1;i<=r;i++)
for(int j=1;j<=c;j++)
scanf("%lf%lf%lf",&p1[i][j],&p2[i][j],&p3[i][j]);
dp[r][c]=0;
memset(dp,0,sizeof(dp));
for(int i=r;i>0;i--)
for(int j=c;j>0;j--)
{
if(i==r&&j==c)
continue;
if(p1[i][j]==1)//p1为1,原地不动该点期望为0;
{
dp[i][j]=0;
continue;
}
dp[i][j]=(2+p2[i][j]*dp[i][j+1]+p3[i][j]*dp[i+1][j])/(1-p1[i][j]);
} printf("%.3f\n",dp[1][1]);
}
return 0;
}

hdu3853 LOOPS(概率dp) 2016-05-26 17:37 89人阅读 评论(0) 收藏的更多相关文章

  1. 转自知乎,亲民好酒推荐 分类: fool_tree的笔记本 2014-11-08 17:37 652人阅读 评论(0) 收藏

    这里尽量为大家推荐一些符合大众喜好.业内公认好评."即使你不喜欢,你也会承认它不错"的酒款.而且介绍到的酒款还会有一个共同的特征,就是能让你方便的在网上买到. 大概会分为烈酒,利口 ...

  2. 搭建hbase-0.94.26集群环境 分类: B7_HBASE 2015-01-24 17:14 861人阅读 评论(0) 收藏

    先安装hadoop1.2.1,见http://blog.csdn.net/jediael_lu/article/details/38926477 1.配置hbase-site.xml <prop ...

  3. APP被苹果APPStore拒绝的各种原因 分类: ios相关 app相关 2015-06-25 17:27 200人阅读 评论(0) 收藏

    APP被苹果APPStore拒绝的各种原因 1.程序有重大bug,程序不能启动,或者中途退出. 2.绕过苹果的付费渠道,我们之前游戏里的用兑换码兑换金币. 3.游戏里有实物奖励的话,一定要说清楚,奖励 ...

  4. The 3n + 1 problem 分类: POJ 2015-06-12 17:50 11人阅读 评论(0) 收藏

    The 3n + 1 problem Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 53927   Accepted: 17 ...

  5. Hdu428 漫步校园 2017-01-18 17:43 88人阅读 评论(0) 收藏

    漫步校园 Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Submissi ...

  6. Java中的日期操作 分类: B1_JAVA 2015-02-16 17:55 6014人阅读 评论(0) 收藏

    在日志中常用的记录当前时间及程序运行时长的方法: public void inject(Path urlDir) throws Exception { SimpleDateFormat sdf = n ...

  7. 人活着系列之平方数 分类: sdutOJ 2015-06-22 17:10 7人阅读 评论(0) 收藏

    人活着系列之平方数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 偶然和必然?命运与意志?生与死?理性与情感?价值与非价值?在&quo ...

  8. MessageFlood 分类: 串 2015-06-18 17:00 10人阅读 评论(0) 收藏

    MessageFlood TimeLimit: 1500ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Well,how do you feel about mobil ...

  9. Hdu 1429 胜利大逃亡(续) 分类: Brush Mode 2014-08-07 17:01 92人阅读 评论(0) 收藏

    胜利大逃亡(续) Time Limit : 4000/2000ms (Java/Other)   Memory Limit : 65536/32768K (Java/Other) Total Subm ...

随机推荐

  1. hibernate的异常 Session was already closed

    今天写hibernate时候遇到一些异常 代码: Session session = sessionFactory.getCurrentSession(); session.beginTransact ...

  2. 吴裕雄 实战PYTHON编程(5)

    text = '中华'print(type(text))#<class 'str'>text1 = text.encode('gbk')print(type(text1))#<cla ...

  3. KKT条件的物理意义(转)

    最好的解释:https://www.quora.com/What-is-an-intuitive-explanation-of-the-KKT-conditions# 作者:卢健龙链接:https:/ ...

  4. SciTE: 中文字符支持问题

    SciTE: 中文字符支持问题   SciTE(Scintilla Text Editor)是一个体积小巧的文本编辑器. 但是它默认的设置对中文字符处理不好,其实只要对它进行相应的配置,就可以了. 1 ...

  5. linux 配置Tomcat开机启动

    一台安装有tomcat的linux服务器 方法/步骤   1 请自行下载安装配置tomcat的服务器环境 本经验仅仅介绍如何配置tomcat的开机自动启动 2 切换到tomcat/bin目录下 用vi ...

  6. 消息 14607,级别 16,状态 1,过程 sp_send_dbmail,第 141 行 profile 名称无效

    错误:消息 14607,级别 16,状态 1,过程 sp_send_dbmail,第 141 行profile 名称无效 原因: 用SA帐户是可以发送邮件的,但换了另外一个帐户后却提示以上错误. 解决 ...

  7. Django的模板语言介绍

    模板语言: 1.我们先看下在命令行中渲染模板 先导入模块对象 2.渲染一个变量 <p>当前时间:{{ time }}</p> return render(request,&qu ...

  8. java里的静态成员变量是放在了堆内存还是栈内存

    转自http://bbs.csdn.NET/topics/370001490 堆区: 1.存储的全部是对象,每个对象都包含一个与之对应的class的信息.(class的目的是得到操作指令) 2.jvm ...

  9. Spring框架的事务管理的分类

    1. Spring的事务管理的分类 1. Spring的编程式事务管理(不推荐使用) * 通过手动编写代码的方式完成事务的管理(不推荐) 2. Spring的声明式事务管理(底层采用AOP的技术) * ...

  10. 使用threejs点云秀出酷炫的图片效果(一)

    来源:http://blog.csdn.net/srk19960903/article/details/70214556 使用了点云拼凑出了照片轮播十分有趣,于是用threejs实现这个效果. 首先这 ...