Heads or tails

Anna and Ivet toss coins. Anna will win the game after m heads, and Ivet
will win after n tails (whichever happens first). They have n coins,
each with a probability p_(i) of landing heads (and a probability
1 − p_(i) of landing tails). They start tossing the first coin. Anna,
who chose the rules, decided that the same coin will be used as long as
it lands heads, and that after landing tails the next coin will be used.
How likely will Anna win?

Input

Input consists of several cases, each with m, n and the n probabilities.
You can suppose 1 ≤ m, n ≤ 1000.

Output

For every case, print the probability that Anna wins with 4 digits after
the decimal point.

Problem information

Author: Unknown
Translator: Salvador Roura

Generation: 2026-01-25T10:15:12.370Z

© Jutge.org, 2006–2026.
https://jutge.org
