第四届 The number of steps
2015-05-05 18:38
375 查看
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 <iostream> #include <cstdio> #include <math.h> #include <iomanip> #include <cstring> #include <cstdlib> #include <algorithm> #include <string> #include <queue> using namespace std; int main() { int N; while(cin>>N&&N!=0) { double A[50][50]={0.0}; double a,b,c,d,e; cin>>a>>b>>c>>d>>e; A[N][1]=0; for(int i=2;i<=N;i++) A[N][i]=A[N][i]+A[N][i-1]+1; for(int i=N-1;i>=1;i--) for(int j=1;j<=i;j++) { if(j==1) A[i][j]+=a*(A[i+1][j]+1)+b*(A[i+1][j+1]+1); else A[i][j]+=e*(A[i][j-1]+1)+d*(A[i+1][j+1]+1)+c*(A[i+1][j]+1); } cout<<setiosflags(ios::fixed)<<setprecision(2); cout<<A[1][1]<<endl; } return 0; }
相关文章推荐
- 2013山东省第四届ACM省赛 The number of steps
- 第四届 山东省ACM The number of steps (概率dp 待整理)
- 山东省第四届ACM大学生程序设计竞赛 The number of steps 概率dp
- I:The number of steps
- SDUT 2623:The number of steps
- UPC:2225 The number of steps(概率DP)
- upc 2225 The number of steps 期望DP
- 13年山东省赛——The number of steps
- sdut 2623 The number of steps (概率dp)
- 13年山东省赛 The number of steps(概率dp水题)
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
- The number of steps - UPC 2225 dp
- sdut2623——The number of steps
- [2013山东ACM省赛] The number of steps (概率DP,数学期望)
- sdutoj 2623 The number of steps
- The number of steps
- UPC2225: The number of steps
- B - Minimum number of steps
- HDU 4727 The Number Off of FFF (水)
- 9 To view the results of a manual SQL Tuning Advisor task, which steps should the DBA take? A. From