Heads or tails

Anna and Ivet toss coins. Anna will win the game after mm heads, and Ivet will win after nn tails (whichever happens first). They have nn coins, each with a probability pip_i of landing heads (and a probability 1pi1 - 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 mm, nn and the nn probabilities. You can suppose 1m,n10001 \le m, n \le 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