Flipping Coins
Time limit4sMemory limit512 MB
Given N coins all tails and exactly K fair tosses chosen adaptively, find the maximum expected number of heads at the end.
- Level
Medium7 of 10
- Topics
- Probability, Dynamic programming, Greedy
- Solved
- No attempts yet
Problem
Line up identical coins in a row. Every coin starts tails up. Exactly times you pick one coin, toss it into the air and put it back where it was. The coin lands heads up with probability and tails up with probability . Once all tosses are done, you keep every coin that is heads up.
You choose which coin to toss right before each toss, after seeing all the results so far. All tosses must happen, and you cannot stop early even when every coin is already heads up.
Find the expected number of coins you keep when you choose the coins so that this expectation is as large as possible.
Input
One line with two space separated integers and . is the number of coins () and is the number of tosses you must perform ().
Output
Print the largest expected number of coins that are heads up at the end, rounded to six decimal places, on one line. Print all six digits after the decimal point, and round an exact halfway value upward.