Probability of getting 'k' heads with 'n' coins This is an interview question.( http://www.geeksforgeeks.org/directi-interview-set-1/)
Given $n$ biased coins, with each coin giving heads with probability $P_i$, find the probability that on tossing the $n$ coins you will obtain exactly $k$ heads. You have to write the formula for this (i.e. the expression that would give $P (n, k)$).
I can write a recurrence program for this, but how to write the general expression ?

Let us say p = Pi, and q = 1 - Pi.
Then the probability of a given sequence, e.g., 100010..., in which k heads appear in n flips  e.g pqqqpq... can be given by
$$p^k.q^{n-k}$$
There are a total of $2^n$ possible sequences. Only some of these give k heads and n - k tails. Their number is
$$\frac{n!}{k! (n-k)!} = {n \choose k}$$
Since any one or another of these sequences will do, the probability that exactly k heads occur in n flips would be
$${n \choose k}p^k.q^{n-k}$$
[Source]
