Flipping Coins
InterviewTime limit2sMemory limit512 MB
Each step flips a uniformly random set of A_i coins; find the expected number of heads after all K steps.
- Level
Medium6 of 10
- Topics
- Probability, Dynamic programming, Combinatorics
- Solved
- No attempts yet
Problem
There are coins on a table. Every coin starts heads up.
You are given integers . In the first step you choose coins at random and flip them, in the second step you choose coins at random and flip them, and you repeat this until the -th step. Each step picks one of the sets of size uniformly at random, independently of what the earlier steps did.
Compute the expected number of coins that are heads up after all steps are done.
Input
The first line contains the number of coins ().
The second line contains the number of steps ().
The third line contains (), separated by spaces.
Output
Print, on one line, the expected number of coins that are heads up after all steps are done.
Round the value at the eleventh digit after the decimal point so that exactly 10 digits follow the decimal point. Round a half up. Pad with zeros when the value is an integer, so an expected value of prints as 0.0000000000.
Hint
Take and . The first step flips 2 coins, which leaves 1 head and 2 tails. The second step has two possible outcomes.
- It picks the 2 tails and flips them. The probability is and the number of heads becomes 3.
- It picks 1 head and 1 tail and flips them. The probability is and the number of heads becomes 1.
The expected value is .