#1665. The number of steps

    ID: 1665 传统题 1000ms 32MiB 尝试: 0 已通过: 0 难度: (无) 上传者: 标签>2013山东省省赛动态规划期望数学概率

The number of steps

The number of steps

题目描述

本题为2013年山东省省赛PROBLEM I

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?

输入说明

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.

输出说明

Please calculate the expected number of steps required to reach the KEY room, there are 2 digits after the decimal point.

样例

输入

3
0.3 0.7
0.1 0.3 0.6
0

输出

3.41