山东省第四届ACM大学生程序设计竞赛 The number of steps 概率dp
来源:互联网 发布:uboot源码下载 编辑:程序博客网 时间:2024/06/18 00:48
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?
输入
输出
示例输入
30.3 0.70.1 0.3 0.60
示例输出
3.41
提示
来源
示例程序
主人公站在一个金字塔顶端往下面走
规定只能往左 下 左下 走然后对应相对的概率
求从1,1到n,n的期望
有点像数塔从底往上推求得
ACcode:
#include <map>#include <queue>#include <cmath>#include <cstdio>#include <cstring>#include <stdlib.h>#include <iostream>#include <algorithm>#define maxn 100using namespace std;double dp[maxn][maxn];double a,b,c,d,e;int n;int main(){ while(scanf("%d",&n),n){ scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e); memset(dp,0,sizeof(dp)); for(int i=n-1;i>0;--i) dp[n][i]+=dp[n][i+1]+1; for(int i=n-1;i>0;--i){ dp[i][i]+=a*(dp[i+1][i+1]+1)+b*(dp[i+1][i]+1); for(int j=i-1;j>0;--j) dp[i][j]+=c*(dp[i+1][j+1]+1)+d*(dp[i+1][j]+1)+e*(dp[i][j+1]+1); } printf("%.2lf\n",dp[1][1]); } return 0;}
- 山东省第四届ACM大学生程序设计竞赛 The number of steps 概率dp
- 山东省第四届ACM大学生程序设计竞赛 The number of steps(概率dp&全期望)
- 第四届 山东省ACM The number of steps (概率dp 待整理)
- 山东省第四届ACM大学生程序设计竞赛 Mountain Subsequences dp
- 山东省第四届ACM大学生程序设计竞赛 Rescue The Princess
- 山东省第四届ACM大学生程序设计竞赛 Rescue The Princess
- 2013山东省第四届ACM省赛 The number of steps
- 第四届 山东省ACM大学生程序设计竞赛
- 2013年山东省第四届ACM大学生程序设计竞赛
- 山东省第四届ACM大学生程序设计竞赛Mountain Subsequences
- 山东省第四届ACM大学生程序设计竞赛 Alice and Bob
- Mountain Subsequences(山东省第四届ACM大学生程序设计竞赛)
- 山东省第一届ACM大学生程序设计竞赛--Greatest Number--二分
- [2013山东省第四届ACM大学生程序设计竞赛]——Rescue The Princess
- 2013年山东省第四届ACM大学生程序设计竞赛——Rescue The Princess
- 2013年山东省第四届ACM大学生程序设计竞赛:Rescue The Princess
- 山东省第四届ACM大学生程序设计竞赛-Rescue The Princess(计算几何)
- Rescue The Princess(山东省第四届ACM大学生程序设计竞赛 )
- 剑指offer(六)之变态跳台阶
- 练习二1010
- EasyPusher安卓Android手机直播推送之RTSP流媒体协议流程
- 如何设计一个自动布局库:以SDAutoLayout为例
- 练习二1010
- 山东省第四届ACM大学生程序设计竞赛 The number of steps 概率dp
- maven安装最佳实践
- Android真机adb被酷狗等流氓软件抢占进程最好的解决办法
- 神奇的位运算
- 在字符串中有序插入一个新字符
- Mybatis传递多个参数
- 使用Docker快速打包和部署运行Disconf
- 大数求和
- Intent和PendingIntent的区别