SPOJ:Robot(数学期望)

There is a robot on the 2D plane. Robot initially standing on the position (0, 0). Robot can make a 4 different moves:

  1. Up (from (x, y) to (x, y + 1)) with probability U.
  2. Right (from (x, y) to (x + 1, y)) with probability R.
  3. Down (from (x, y) to (x, y - 1)) with probability D.
  4. Left (from (x, y) to (x - 1, y)) with probability L.

After moving N times Robot gets points.

  • Let x1 be the smallest coordinate in X-axis, that Robot reached in some moment.
  • Let x2 be the largest coordinate in X-axis, that Robot reached in some moment.
  • Let y1 be the smallest coordinate in Y-axis, that Robot reached in some moment.
  • Let y2 be the largest coordinate in Y-axis, that Robot reached in some moment.

Points achieved by Robot equals to x2 - x1 + y2 - y1.

Given N, U, R, D, L. Calculate expected value of points that Robot achieved after N moves.

Input

First line: One interger N (1 ≤ N ≤ 200).

Second line: Four real numbers U, R, D, L (U + R + D + L = 1, 0 ≤ U, R, D, L ≤ 1) with maximum of 6 numbers after dot.

Output

One number: expected value of points achieved by Robot. The answer will be considered correct if its relative or absolute error does not exceed 10-6.

Example 1

Input:
2
0.100000 0.200000 0.300000 0.400000
Output:
1.780000

Example 2

Input:
3
0.25 0.25 0.25 0.25
Output:
2.375000

题意:二维平面上一个机器人,给出机器人走的步数,已经走上下左右的概率;机器人走到最右边是Xmax,最左边是Xmin,上下同理。问机器人Xmax-Xmin+Ymax-Ymin的期望。

思路:。。

猜你喜欢

转载自www.cnblogs.com/hua-dong/p/9046505.html