SDUT 2623 The number of steps (概率)
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?
输入
In each case , first Input a positive integer n(0
输出
示例输入
3
0.3 0.7
0.1 0.3 0.6
0
示例输出
3.41
提示
来源
#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 (概率)的更多相关文章
- sdutoj 2623 The number of steps
http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&problemid=2623 The number of steps ...
- The number of steps(概率dp)
Description Mary stands in a strange maze, the maze looks like a triangle(the first layer have one r ...
- SDUT 2623:The number of steps
The number of steps Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Mary stands in a stra ...
- sdut2623--The number of steps(概率dp第一弹,求期望)
The number of steps Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描写叙述 Mary stands in a st ...
- 13年山东省赛 The number of steps(概率dp水题)
转载请注明出处: http://www.cnblogs.com/fraud/ ——by fraud The number of steps Time Limit: 1 Sec Me ...
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- centos6.8安装具有ngx_cache_purge模块的nginx1.10.3
CentOS-6.8 安装 Nginx1.10.3Nginx 环境准备:安装Nginx需要完成以下依赖的安装 1.gcc 安装:yum install gcc-c++ 2.PCRE pcre-deve ...
- iOS开发-Quartz2D初识
Quartz2D如果单独的从Quartz,那么会发现Quartz是一个开源的Java作业调度框架,单独从英文翻译的角度来看的话Quartz的英文是石英,如果有的时候不小心搜索会发现手表推荐.本文中介绍 ...
- 游戏服务器框架:Leaf/go
Leaf 是一个使用 Go 语言开发的开源游戏服务器框架,注重运行效率并追求极致的开发效率.Leaf 适用于几乎所有的游戏类型.其主要的特性: 良好的使用体验.Leaf 总是尽可能的提供简洁和易用的接 ...
- Druid对比Elasticsearch
我们不是Elasticsearch的专家, 如果描绘有误, 请通过邮件列表或者其他途径告知我们. Elasticsearch 是基于Apache Lucene搜索服务器. 提供了对无模式文档的全文检 ...
- [置顶] 自定义的解压进度条 关于ProgressBar的使用
整体布局 <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...
- TreeListControl:设置行样式
<Style x:Key="OddEvenRowStyle" TargetType="{x:Type dxg:GridRowContent}"> & ...
- 从头认识java-特辑-你不知道的main函数
这一章节我们来讨论一下main函数. 对于这个函数大家都不陌生,并且都习以为常.可是当中有一些东西,还是值得我们去总结的. 1.普通的main package com.ray.test; public ...
- MySQL数据源在Spring中的配置
干脆把MySQL的数据源配置也一起放这里,以备不时之需. MySQL的驱动包可以从这里 http://pan.baidu.com/s/1d02aZ 下载. 以下粗体部分是需要你根据实际情况调整的. & ...
- 在Foreda8中整合Apche httpd2.4.6和Tomcat7.0.42(使用tomcat-connectors-1.2.37)
本地Apche httpd2.4.6(http://pan.baidu.com/share/link?shareid=4003375081&uk=34256769)和Tomcat7.0.42是 ...
- matlab工作空间,变量的保存和载入
对于工作空间中变量的保存和载入可以使用save和load命令,详细的使用方法通过help指令获取(help save,help load). 两条指令最常用的情况为: 1.% 保存整个工作空间至指定 ...