Compute the best possible chance of growing A dollars to V dollars with capped doubling bets and report the largest opening bet that reaches it.
Medium6Dynamic programmingProbabilityGame theoryNo attempts yetTime limit10sMemory limit512 MBYour team of explorers is stuck in a hotel casino called the Google Royale. To leave, you have to gamble your way to enough money to buy the hotel for V dollars.
You start with A dollars and you play betting rounds until one of two things happens. If a betting round ends with 0 dollars or less, you lose. If a betting round ends with V dollars or more, you buy the hotel and leave. Otherwise you start another betting round.
A betting round is one or more coin flips. If you hold X dollars when the round starts, you pick an integer B with 1≤B≤min(X,M) and bet B dollars on the first flip.
Every flip is fair. Winning a flip pays you the amount bet on that flip and ends the round at once. Losing a flip puts you in debt for the amount bet on it. After a loss you may pay what you owe and end the round, or, when twice the last bet is at most M, flip again with the bet doubled. The bets inside one round therefore run B, 2B, 4B, 8B and so on, and the doubling stops when you win a flip, when you decide to stop, or when the next bet would exceed M. You may keep doubling even when the bets already placed in this round add up to more than X.
When the round ends you settle it: you pay for every flip you lost, and the Royale pays you for the single flip you won, if there was one. Say you open with a bet of 1, lose three flips, then win the fourth. You collect 8 and pay 4 + 2 + 1, so you gain 1 dollar. If instead you stop after those three losses, you pay 4 + 2 + 1 and lose 7 dollars. If the settlement leaves you with 0 dollars or less, you are broke and the game is over.
An android in your team computes the probability that you win when you play optimally. Print that probability, together with the largest first bet of the opening round that still attains it. No bet may ever exceed M.
Take A=5, M=20 and V=20, and suppose you play the strategy below, which is not optimal.
The first line has the number of test cases T. Each of the next T lines has three integers A, M and V separated by single spaces.
For each test case print one line in the form Case #x: y z, where x is the case number starting from 1, y is the probability of winning under an optimal strategy, and z is the largest first bet that attains that probability. Print y rounded to exactly six digits after the decimal point.