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. jdk与eclipse版本问题解决applet的启动

    今天在中韩,遇到一个保全项目,需要调用applet显示打印批单,结果IE一直显示安全设置问题,去java程序的安全里面想下调等级,不好调,所以想改个jdk_32试试. 版本环境 原先是eclipse_ ...

  2. PostgreSQL:安装

    官网地址:https://www.postgresql.org/ 安装文件下载地址:http://www.enterprisedb.com/products-services-training/pgd ...

  3. 安装shopex注意事项

    [原创]关于PHP5.3.x和Zend Optimizer(Zend Guard Loader),以及shopex4.8.5安装的问题  http://dzmailbox.blog.163.com/b ...

  4. Snapchat面经(师兄的)

    给一个LinkedList环,给其中任一个节点的reference,求删去LinkedList中所有value=k的点 我的想法:假设给定的点事ListNode oneNode, 设置ListNode ...

  5. php4.3.4.4、apache2.0.4.8、mysql 4.0.26、window7 配置过程

    apache的安装不需要过程,直接默认安装,下一步 下一步就Ok了. php4的安装: 1 将php-4.0.4-Win32.zip(最新版本4.0.4)解压缩到硬盘的一个目录中,例如解压到E:php ...

  6. 一个标准的ECharts代码

    <!DOCTYPE html> <head> <meta charset="utf-8"> <title>ECharts</t ...

  7. java mvc控制器基本传值方式

    控制器----- @RequestMapping(value = "MatchDetail", method = RequestMethod.GET) public ModelAn ...

  8. 算法第四版 在Eclipse中调用Algs4库

    首先下载Eclipse,我选择的是Eclipse IDE for Java Developers64位版本,下载下来之后解压缩到喜欢的位置然后双击Eclipse.exe启动 然后开始新建项目,File ...

  9. SQL 中常见的系统存储过程

    -- 来源于网络 -- 更详细的介结参考联机帮助文档 xp_cmdshell --*执行DOS各种命令,结果以文本行返回. xp_fixeddrives --*查询各磁盘/分区可用空间 xp_logi ...

  10. 8007003Windows Update遇到未知错误

    如果在检查更新时收到 Windows Update 错误 80070003,则需要删除 Windows 用于标识计算机更新的临时文件.若要删除临时文件,请停止 Windows Update 服务,删除 ...