405164: GYM101808 D Simplified 2048

Memory Limit:256 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

D. Simplified 2048time limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard output

Ahmad was playing the famous game 2048, however, he found it very hard. He decided to create a simplified version of it on 1 dimension.

Basically, he has an array of length n that is initially empty.

He starts with a score of zero, then, the following steps are repeated until the array is full:

  1. A number appears in the right-most cell of the array. Either a 4 with probability , or a 2 with probability .
  2. All the cells are shifted once to the left by applying the following algorithm:

    Go through the array from left to right, for each cell that contains a number, there are 3 options:

    • if the cell to the left of it is empty, move it one step to the left.
    • if the cell to the left of it has a number equal to the current number, add the sum of both numbers (twice the current number) to the score, empty the current cell, and multiply the number in the cell to the left of it by 2.
    • if the cell to the left of it has a number not equal to the current number, do nothing.

    for example, this array:

    may become (with probability ) :

Soon, he realized that this game depends only on luck. To see how lucky he is, he asked you to find the expected score at the end of the game.

Input

The first line of input contains one integer T, the number of test cases.

Each test case contains two integers n, the number of cells, and p, the probability that the new number is 4. (1 ≤ n ≤ 16) (0 ≤ p ≤ 100)

Output

For each test case output one line containing the expected score.

Your answer will be considered correct if the relative error is less than 10 - 6.

ExampleInput
3
1 50
2 25
3 20
Output
0.000000
3.875000
15.725298

加入题单

上一题 下一题 算法标签: