So You Want to Be a 2ⁿ-aire?

Time limit1sMemory limit128 MB

Summary
A contestant with a current prize faces n questions; each question's success chance p is uniform on [t,1]. Find the optimal expected prize, to three decimals.
Level

Medium7 of 10

Topics
Dynamic programming, Probability, Math, Binary search
Solved
No attempts yet

Problem

A contestant starts with a prize of $1 and is asked a sequence of nn questions. For each question, the contestant may:

  • quit and keep the current prize;
  • answer the question. If the answer is wrong, the contestant quits with nothing. If it is correct, the prize is doubled and the contestant continues to the next question.

After the last question, the contestant quits with the current prize. The contestant wants to maximize the expected prize.

Once a question is asked, the contestant can assess the probability pp of answering it correctly. For each question, assume pp is a random variable uniformly distributed over the interval [t,1][t, 1].

Input

The input consists of several lines. Each line contains two numbers: an integer nn (1≤n≤301 \le n \le 30) and a real number tt (0≤t≤10 \le t \le 1). The input is terminated by a line containing 0 0, which must not be processed.

Output

For each pair nn and tt, print the expected prize the contestant earns when playing the optimal strategy, rounded to three decimal places.

Examples3

  1. Example 1

    Input
    1 0.5
    1 0.3
    2 0.6
    24 0.25
    0 0
    
    Expected output
    1.500
    1.357
    2.560
    230.138
    
  2. Example 2

    Input
    1 1
    5 1
    30 1
    0 0
    
    Expected output
    2.000
    32.000
    1073741824.000
    
  3. Example 3

    Input
    1 0.0
    1 0.25
    1 0.5
    1 0.75
    1 1.0
    0 0
    
    Expected output
    1.250
    1.333
    1.500
    1.750
    2.000