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大学生程序设计竞赛
 
 
 
第一行有一个位置,第二行两个,第三行三个......第n行n个。此时你在最左上角的位置,如果你左面没有位置,只能往左下和右下走,概率(a,b)。否则可以往左,左下和右下三个方向走,,概率(c,d,e)。让你求到达最左下角的期望。
 
而我们可以逆向推导,即从最左下角走向最顶端,,自己推推。。。。。。。。
 
#include<iostream>
#include<cstdio>
#include<cstring> using namespace std; double dp[][];
double a,b,c,d,e; int main(){ //freopen("input.txt","r",stdin); int n;
while(~scanf("%d",&n) && n){
scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e);
memset(dp,,sizeof(dp));
dp[n][n]=;
for(int j=n-;j>=;j--) //初始化最底下一行(即第n行)
dp[n][j]+=*(dp[n][j+]+);
for(int i=n-;i>=;i--){
dp[i][i]+=a*(dp[i+][i+]+)+b*(dp[i+][i]+); //初始化n-1~1行的最左边的位置
for(int j=i-;j>=;j--)
dp[i][j]+=c*(dp[i+][j+]+)+d*(dp[i+][j]+)+e*(dp[i][j+]+); //初始化n-1~1行的除了最左边的位置的期望值
}
printf("%.2lf\n",dp[][]);
}
return ;
}

SDUT 2623 The number of steps (概率)的更多相关文章

  1. sdutoj 2623 The number of steps

    http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2623 The number of steps ...

  2. The number of steps(概率dp)

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

  3. SDUT 2623:The number of steps

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

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

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

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

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

  6. [2013山东ACM]省赛 The number of steps (可能DP,数学期望)

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

  7. Minimum number of steps CodeForces - 805D(签到题)

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  8. Codeforces Round #411 div 2 D. Minimum number of steps

    D. Minimum number of steps time limit per test 1 second memory limit per test 256 megabytes input st ...

  9. codeforce 804B Minimum number of steps

    cf劲啊 原题: We have a string of letters 'a' and 'b'. We want to perform some operations on it. On each ...

随机推荐

  1. OTL翻译(4) -- otl_stream类

    otl_stream Otl_stream是具体实现otl_stream_concept的类.任何的SQL语句.SQL语句块和存储过程都能通过otl_stream进行处理. 传统的数据库API处理SQ ...

  2. 网页IE轻松调用VLC播放器实现监控(组件+方法大全)【转】

    公司突发奇想,要把刚买回来的网络监控机用自己内部网站在线监控. 作为网站的开发员,我接下了这个任务. 网络上有很多资料参与,但是都不全都不尽人意,最后经过多次的不同关键字的查找和测试,总算让我成功了. ...

  3. [leetcode]Populating Next Right Pointers in Each Node II @ Python

    原题地址:https://oj.leetcode.com/problems/populating-next-right-pointers-in-each-node-ii/ 题意: Follow up ...

  4. AS .ignore插件 忽略文件

    AS自带的.ignore文件 在AS中新建项目时,默认会创建一个.ignore文件,其中默认忽略的是 *.iml .gradle /local.properties /.idea/workspace. ...

  5. [置顶] 利用Global.asax的Application_Error实现错误记录,错误日志

    利用Global.asax的Application_Error实现错误记录 错误日志 void Application_Error(object sender, EventArgs e) { // 在 ...

  6. 解决Sqlserver 2008 R2在创建登录名出错"此版本的 Microsoft Windows 不支持 MUST_CHANGE 选项。 (Microsoft SQL Server,错误: 15195)"

    错误信息:   执行 Transact-SQL 语句或批处理时发生了异常. (Microsoft.SqlServer.ConnectionInfo)   此版本的 Microsoft Windows ...

  7. cygwin64安装wget和apt-cyg

    说实话,网上的教程要么不适用,要么不能用,唯有多次试错之后才杀出一条血路. 1.安装cygwin 2.勾选wget 这个如果忘记勾选了,就再次打开setup.exe,选择如下操作,即可. 然后点击下一 ...

  8. 修改linux的文件时,如何快速找到要修改的内容并修改

    修改linux系统下的文件时,如果文件内容很多,不容易找到需要修改的内容,下面详细介绍linux系统下如何快速修改文件. 工具/原料   linux系统 方法/步骤     在linux系统下,找到需 ...

  9. 用Java发送HTML格式邮件测试类(支持中文)

    代码由纯Java写成,支持中文,一目了然,只要将Main函数中的相关信息填写正确就直接用了,便于修改,可以在此类基础上任意扩展成自己的类. 注意做HTML形式的邮件,最好把HTML,CSS都写全,只写 ...

  10. css选择器顺序的小技巧

    在线演示 本地下载 css的选择器的顺序其实很有意思,如果应用的好的话,可以做一些简单的逻辑出来,配合上css3,就可以尽可能的脱离js了. 这里的演示是一个带有hover事件的四张照片,效果来自一个 ...