A trader starts the night with a bankroll of a chips and plays rounds of a fixed game: each round they win one chip with probability p and lose one chip with probability 1 - p, independently. They stop when the bankroll reaches N chips (target) or 0 chips (bust).
Compute the probability that the trader reaches the target before going bust.
Three values p, a and N — p with at most 6 digits after the decimal point, a and N integers.
One real number: the probability of reaching N before 0, with relative error at most 1e-9. Note that the probability can be extremely small; your output must be relatively accurate, not just close to zero.
0.05 <= p <= 0.95
1 <= a < N <= 150
This is a standard problem: a submission scores full points if it produces the correct output for every test case, and zero otherwise.
Numeric answers are accepted if they are within a relative tolerance of 1e-09 of the expected value.
0.5 3 10
3.000000000000000e-01
0.45 10 20
1.185005313401287e-01