Premium problem86. Exactly k Heads From a Biased Coin

Easy Locked

Return the probability of exactly k heads in n independent tosses of a coin that lands heads with probability p.

P(X=k)=(nk)pk(1−p)n−kP(X = k) = \binom{n}{k} p^k (1-p)^{n-k}

The binomial coefficient counts which tosses were heads; the powers give the probability of any one such arrangement.

Input

n = 10
k = 3
p = 0.5

Output

0.1171875

Premium problem

This one's part of Premium. Unlock the full Probability track plus every other premium problem on the site.

Implement solve(...)