The number of steps
2013-08-13 16:06
399 查看
Description
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?
Input
There are no more than 70 test cases.
In each case , first Input a positive integer n(0<n<45), which means the layer of the maze, then Input five real number a, b, c, d, e. (0<=a,b,c,d,e<=1, a+b=1, c+d+e=1).
The input is terminated with 0. This test case is not to be processed.
Output
Please calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.
Sample Input
Sample Output
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?
Input
There are no more than 70 test cases.
In each case , first Input a positive integer n(0<n<45), which means the layer of the maze, then Input five real number a, b, c, d, e. (0<=a,b,c,d,e<=1, a+b=1, c+d+e=1).
The input is terminated with 0. This test case is not to be processed.
Output
Please calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.
Sample Input
30.3 0.70.1 0.3 0.60
Sample Output
3.41
#include<stdio.h> #include<string.h> using namespace std; int main() { int n; double dp[150][150]; double a,b,c,d,e; while(scanf("%d",&n)&&n) { scanf("%lf%lf%lf%lf%lf",&a,&b,&c,&d,&e); memset(dp,0,sizeof(dp)); dp =0; for(int j=n-1;j>=1;j--) dp [j]+=1*(dp [j+1]+1);//初始化最后一行 for(int i=n-1;i>=1;i--) { dp[i][i]+=a*(dp[i+1][i+1]+1)+b*(dp[i+1][i]+1);//初始化最左边的房间 for(int j=i-1;j>=1;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; }
相关文章推荐
- 第四届 The number of steps
- sdut 2623 The number of steps (概率dp)
- 2013山东省第四届ACM省赛 The number of steps
- SDUT 2623:The number of steps
- upc 2225 The number of steps 期望DP
- 13年山东省赛——The number of steps
- 13年山东省赛 The number of steps(概率dp水题)
- The number of steps - UPC 2225 dp
- [2013山东ACM省赛] The number of steps (概率DP,数学期望)
- I:The number of steps
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
- 第四届 山东省ACM The number of steps (概率dp 待整理)
- sdut2623——The number of steps
- UPC2225: The number of steps
- UPC:2225 The number of steps(概率DP)
- 山东省第四届ACM大学生程序设计竞赛 The number of steps 概率dp
- sdutoj 2623 The number of steps
- python中关于Np.hstack()错误的ValueError: all the input arrays must have same number of dimensions
- Codeforces Beta Round #27 E. Number With The Given Amount Of Divisors 含n个约数最小数
- POJ 2699 The Maximum Number of Strong Kings Description