sdut2623--The number of steps(概率dp第一弹,求期望)

时间:2022-09-10 18:13:08

The number of steps

Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^

题目描写叙述

Mary stands in a strange maze, the maze looks like a triangle(the first layer have one room,the second layer have two rooms,the third layer have three rooms …). Now she stands at the top point(the first layer), and the KEY of this maze is in the lowest layer’s
leftmost room. Known that each room can only access to its left room and lower left and lower right rooms .If a room doesn’t have its left room, the probability of going to the lower left room and lower right room are a and b (a + b = 1 ). If a room only has
it’s left room, the probability of going to the room is 1. If a room has its lower left, lower right rooms and its left room, the probability of going to each room are c, d, e (c + d + e = 1). Now , Mary wants to know how many steps she needs to reach the
KEY. Dear friend, can you tell Mary the expected number of steps required to reach the KEY?


输入

There
are no more than 70 test cases.
 
In each case , first Input a positive integer n(0
The
input is terminated with 0. This test case is not to be processed.

输出

Please
calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.

演示样例输入

3
0.3 0.7
0.1 0.3 0.6
0

演示样例输出

3.41

提示

 

来源

2013年山东省第四届ACM大学生程序设计竞赛
概率dp的第一道题目,题目比較简单。
到着求解,最后一个点到最后的期望是0,其它的都由它连接的点的期望求出来。
sdut2623--The number of steps(概率dp第一弹,求期望)

watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQvd2luZGRyZWFtcw==/font/5a6L5L2T/fontsize/400/fill/I0JBQkFCMA==/dissolve/70/gravity/SouthEast">

假设i到j的概率是pij,i到i的概率是pii,期望是E,那么求1到4的期望是
1.   E4 = 0 。
2.   E3 =E3 *P33
+ E4 * P34 + 1
;
3.  
E2 = E2 *P22+ E4
* P24 + 1  ;
4.  
E1 =E1 *P11 + E2
*P12 +E3 * P13 + 1
 ;
记忆化搜索,最后推出要求的值
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
double dp[100][100] ;
double a , b , c , d , e ;
int i , j , n ;
int ff(int x,int y)
{
if( x <= n && y >=(n+1)-x )
return 1 ;
return 0 ;
}
void f()
{ return ;
}
int main()
{
while(scanf("%d", &n) && n)
{
scanf("%lf %lf", &a, &b);
scanf("%lf %lf %lf", &c, &d, &e);
memset(dp,0,sizeof(dp));
for(i = n ; i >= 1 ; i--)
{
for(j = (n+1)-i ; j <= n ; j++)
{
if(i == n && j == (n+1)-i) continue ;
else if( i == n )
dp[i][j] = 1.0*( dp[i][j-1] ) + 1.0 ;
else
{
if( j == (n+1)-i )
dp[i][j] = a*dp[i+1][j-1] + b*dp[i+1][j] + 1.0 ;
else
dp[i][j] = c*dp[i+1][j-1] + d*dp[i+1][j] + e*dp[i][j-1] + 1.0 ;
}
}
}
printf("%.2lf\n", dp[1][n]);
}
return 0;
}

sdut2623--The number of steps(概率dp第一弹,求期望)的更多相关文章

  1. The number of steps&lpar;概率dp&rpar;

    Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one r ...

  2. sgu 495&period; Kids and Prizes &lpar;简单概率dp 正推求期望&rpar;

    题目链接 495. Kids and Prizes Time limit per test: 0.25 second(s)Memory limit: 262144 kilobytes input: s ...

  3. hdu 4336 Card Collector (概率dp&plus;位运算 求期望)

    题目链接 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Othe ...

  4. hdu 3853 LOOPS &lpar;概率dp 逆推求期望&rpar;

    题目链接 LOOPS Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 125536/65536 K (Java/Others)Tota ...

  5. 【概率dp】【数学期望】Gym - 101190F - Foreign Postcards

    http://blog.csdn.net/DorMOUSENone/article/details/73699630

  6. &lbrack;TS-A1489&rsqb;&lbrack;2013中国国家集训队第二次作业&rsqb;抽奖&lbrack;概率dp&rsqb;

    概率dp第一题,开始根本没搞懂,后来看了09年汤可因论文才基本搞懂,关键就是递推的时候做差比较一下,考虑新加入的情况对期望值的贡献,然后推推公式(好像还是不太会推qaq...) #include &l ...

  7. 13年山东省赛 The number of steps(概率dp水题)

    转载请注明出处: http://www.cnblogs.com/fraud/          ——by fraud The number of steps Time Limit: 1 Sec  Me ...

  8. &lbrack;2013山东ACM&rsqb;省赛 The number of steps (可能DP,数学期望)

    The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...

  9. SDUT 2623 The number of steps (概率)

    The number of steps Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Mary stands in a stra ...

随机推荐

  1. Django值Cookie基础

    一.什么是Cookie? Cookies就是服务器暂时存放在你的电脑里的资料(.txt格式的文本文件),好让服务器用来辨认你的计算机.当你在浏览网站的时候,Web服务器会先送一小小资料放在你的计算机上 ...

  2. Unsupported configuration attributes&colon; &lbrack;FILE&lowbar;UPLOAD&rsqb;

    Caused by: java.lang.IllegalArgumentException: Unsupported configuration attributes: [FILE_UPLOAD] 情 ...

  3. js中ajax如何解决跨域请求

    js中ajax如何解决跨域请求,在讲这个问题之前先解释几个名词 1.跨域请求 所有的浏览器都是同源策略,这个策略能保证页面脚本资源和cookie安全 ,浏览器隔离了来自不同源的请求,防上跨域不安全的操 ...

  4. rsync参数详解、利用ssh、rsync 实现数据的定时同步

    rsync 简介 rsync(remote synchronize)是一个远程数据同步工具,可通过 LAN/WAN 快速同步多台主机之间的文 件.也可以使用 rsync 同步本

  5. jquery 判断当前上传文件大小限制上传格式 搭配thinkphp实现上传即预览(模拟异步上传)

    在web开发中,最纠结的一项就是文件上传,最近由于项目需要前后摸索了四天在这里分享给大家.如有不足,望指出!! 前台:jquery.easyui.html 后台:thinkphp 主要涉及语言:jqu ...

  6. deepinmind&lpar;转&rpar;

    http://it.deepinmind.com/ 花名有孚,支付宝工程师 有希望加入支付宝的同学,可以把简历发到我的个人邮箱spidercoco@gmail.com

  7. DELPHI中MessageBox的用法 &lpar;转&rpar;

    MessageBox对话框 输入控件的   ImeName属性把输入法去掉就默认为英文输入了 MessageBox对话框是比较常用的一个信息对话框,其不仅能够定义显示的信息内容.信息提示图标,而且可以 ...

  8. openCV(三)---图像缩放

    UIImage *img1 = [UIImage imageNamed:@"1448941176867"]; //将UIImage转换为IplImage格式 IplImage *p ...

  9. 第三篇--Jmeter测试数据库Mysql

    Jmeter模拟100用户访问Mysql数据库 1.将Mysql数据库的驱动[mysql-connector-java-5.1.15-bin.jar]放到jmeter的lib目录下,新建线程组100[ ...

  10. 修改 salt-minion 的 ID 后报错解决方法

    当在搭建 Saltstack 集中化管理平台配置完毕时,启动服务时,不知道是否你也越到过如下报错的现象呢? 报错问题如下: [root@saltstack_web1group_1 ~]# vim /e ...