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

迷失在幽谷中的鸟儿,独自飞翔在这偌大的天地间,却不知自己该飞往何方…

#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
double dp[100][100];
int n;
double a,b,c,d,e;
int main()
{
while(cin>>n&&n)
{
cin>>a>>b>>c>>d>>e;
memset(dp,0,sizeof(dp));
for(int i=2; i<=n; i++)
dp[n][i]+=dp[n][i-1]+1;//处理最后一行
for(int i=n-1; i>=1; i--) //从倒数第二行开始处理
{
dp[i][1]+=a*(dp[i+1][1]+1)+b*(dp[i+1][2]+1);//处理每一行的第一列
for(int j=2; j<=n; j++)
dp[i][j]+=c*(dp[i+1][j]+1)+d*(dp[i+1][j+1]+1)+e*(dp[i][j-1]+1);//处理每一行的除了第一列以外的其它列
}
printf("%.2lf\n",dp[1][1]);
}
return 0;
}

SDUT 2623:The number of steps的更多相关文章

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

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

  2. sdutoj 2623 The number of steps

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

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

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

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

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

  5. 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 ...

  6. 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 ...

  7. Minimum number of steps 805D

    http://codeforces.com/contest/805/problem/D D. Minimum number of steps time limit per test 1 second ...

  8. Codeforces 805D - Minimum number of steps

    805D - Minimum number of steps 思路:简单模拟,a每穿过后面一个b,b的个数+1,当这个a穿到最后,相当于把它后面的b的个数翻倍.每个a到达最后的步数相当于这个a与它后面 ...

  9. The number of steps(概率dp)

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

随机推荐

  1. AWR--导出AWR数据

    SQL> create or replace directory expdp_dir as '/home/oracle/dump'; Directory created. SQL> @$O ...

  2. Mybatis-Plugin插件学习使用方法

    以下教程仅供学习使用,针对于IntelliJ Idea 15中的Mybatis Plugin插件. 作者博客中的教程:http://myoss.github.io/2016/MyBatis-Plugi ...

  3. C++引用(References)

    1.C++引用: 引用就是某一变量(目标)的一个别名, 相当于同一个人有了两个名字, 无论喊哪一个名字实际上都是指的同一个人. 同样, 在引用上, 对引用的操作与对变量直接操作的效果完全一样, 因此, ...

  4. Linux MD5值递归比对目录中的文件是否有修改

    项目上今天遇到检查两个版本的发布包rc1.tar.gz和rc2.tar.gz的一致性,解决方法做个总结,步骤如下 1. 建立文件夹 mkdir test_rc1 test_rc2 2. 文件解压缩 t ...

  5. C#: 异步委托

    http://www.cnblogs.com/yingzhongwen/p/4568350.html 讲了委托与事件,但是对异步委托研究得还不够深入. http://www.cnblogs.com/l ...

  6. HDU 3688 Searchlights(并查集)

    Problem Description There is a piece of grids land of size n×m. Chandler and his team take responsib ...

  7. HDU 3681 Prison Break(BFS+二分+状态压缩DP)

    Problem Description Rompire is a robot kingdom and a lot of robots live there peacefully. But one da ...

  8. ligerUI_入门_001_设置文本能否被编辑、事件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  9. bootstrap, boosting, bagging 几种方法的联系

    http://blog.csdn.net/jlei_apple/article/details/8168856 这两天在看关于boosting算法时,看到一篇不错的文章讲bootstrap, jack ...

  10. beta阶段事后诸葛亮会议

    项目名:约跑 组名:nice! 组长:李权 组员: 韩媛媛 于淼 刘芳芳 宫丽君 Beta Review会议 时间:2016.11.15 地点:冬华楼一楼大厅 会议内容: 约跑APP的Beta Rev ...