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 ;
}
最新文章
- 如何在使用itext生成pdf文档时给文档添加背景图片
- Hyper-V初涉:功能的添加与虚拟机的创建
- Java中的数是用补码表示的检验
- MongoDB 分片的原理、搭建、应用
- Java list的用法排序及遍历
- 夺命雷公狗—angularjs—4—继承和修正继承
- Java [Leetcode 232]Implement Queue using Stacks
- CSS 中的 em单位
- 射频识别技术漫谈(14)&mdash;&mdash;S50与S70存取控制【worldsing笔记】
- ADODB.Connection 错误 &#39;800a0e7a&#39; 未找到提供程序 该程序可能未正确安装
- C++模板:欧拉函数
- VC++共享数据段实现进程之间共享数据
- iOS申请真机调试证书 -- 图文详解
- cassandra 3.x官方文档(4)---分区器
- springboot+vue前后端分离,nginx代理配置 tomcat 部署war包详细配置
- HashMap 与 ConcrrentHashMap 使用以及源码原理分析
- Confluence 6 workbox 配置查询间隔
- Codeforces 1108D - Diverse Garland - [简单DP]
- Xshell存在后门
- winSockets编程(三)最简单的C/S形式