Dynamic Programming21 sections · 916 units
Open in Course

Toss Strange Coins - Problem Statement

Probability with different coins

nn coins with probabilities pip_i of heads. Find probability of exactly kk heads. dp[i][j]dp[i][j] = probability of jj heads in first ii coins. Transition: dp[i][j]=dp[i1][j1]pi+dp[i1][j](1pi)dp[i][j] = dp[i-1][j-1] \cdot p_i + dp[i-1][j] \cdot (1 - p_i). Base: dp[0][0]=1dp[0][0] = 1 (no coins, 0 heads).

Answer: dp[n][k]dp[n][k]. This is the classic probability DP pattern. Each coin contributes independently, and we track the cumulative count. Each coin contributes independently. The product of individual probabilities gives the combined probability.