Becoming a Millionaire
Time limit5sMemory limit512 MB
Bet any fraction of your money each round to maximize the chance of ending with at least one million dollars.
- Level
Hard8 of 10
- Topics
- Dynamic programming, Probability, Math
- Solved
- No attempts yet
Problem
You are invited to the TV show "Would you like to be a millionaire?". The rules are these.
- Before the game starts, the host spins a wheel of fortune to fix , the probability of winning a single bet.
- You start with dollars.
- There are rounds of betting. In each round you may bet any part of the money you hold, including none of it and all of it. The amount you bet does not have to be a whole number of dollars or cents.
- If you win the round, your money grows by the amount you bet. If you lose the round, your money shrinks by the amount you bet.
- After all rounds, you keep your money if you hold $1000000 or more, rounded down to whole dollars. If you hold less than $1000000, you get nothing.
You are given , and . Play so that the chance of becoming a millionaire is as large as possible, and compute the probability of ending with $1000000 or more.
Input
The first line contains the number of test cases .
Each of the next lines contains , and , separated by single spaces.
- is an integer, the number of betting rounds.
- is a real number, the probability of winning a single round.
- is an integer, the starting amount in dollars.
Limits:
- , with at most 6 digits after the decimal point. may also be written as an integer with no decimal point.
Output
For each test case, print one line Case #x: y, where is the test case number starting at 1 and is the probability of becoming a millionaire.
Print rounded to six digits after the decimal point, padded with zeros so that there are always exactly six digits. Round up when the seventh digit is 5. A probability of exactly 1 prints as 1.000000 and a probability of exactly 0 prints as 0.000000.
Hint
With , and , the only way to reach $1000000 is to bet everything in the single round, so the probability is .
With , and you can play so that you still reach $1000000 after losing one round. Here is one such plan.
- You hold $600000 in the first round. Bet $150000.
- After losing the first round you hold $450000. Bet $100000.
- After losing the first round and winning the second you hold $550000. Bet $450000.
- After winning the first round you hold $750000. Bet $250000.
- After winning the first round and losing the second you hold $500000. Bet $500000.