This article delves into the coupon collector's problem, a classic probability puzzle. The scenario involves a brand of crispy instant noodles where each box contains a random coupon. There are 108 unique coupons in total. The objective is to determine the probability of collecting all 108 coupons when buying 'n' boxes, given that 'n' is greater than or equal to 200.

To solve this problem, we can employ a recursive approach. We define a function P(x, y) that represents the expected number of additional boxes needed to collect the remaining 'y' coupons, given that 'x' coupons have already been collected. This function can be expressed recursively as:

P(x, y) = 1 + (y / 108) * P(x+1, y-1) + ((108 - y) / 108) * P(x, y-1)

The term P(x+1, y-1) represents the scenario where the next box contains a new coupon, increasing the collected coupons by one and reducing the remaining types by one. P(x, y-1) represents the scenario where the next box does not contain a new coupon, leaving the collected coupons unchanged but reducing the remaining types by one.

Our primary goal is to calculate the probability of P(0, 108) when 'n' is greater than or equal to 200. This probability indicates the likelihood of collecting all 108 coupons when starting with zero collected coupons.

To efficiently compute this probability, we can utilize dynamic programming. We initialize an array 'P' where P[i][j] represents the expected number of boxes required to collect the remaining 'j' coupons after having collected 'i' coupons. We can then calculate P[0][108] using the following Python code:

n = 200
P = [[0] * 109 for _ in range(n+1)]
P[0][0] = 0

for i in range(n+1):
    for j in range(1, 109):
        P[i][j] = 1 + (j / 108) * P[i+1][j-1] + ((108 - j) / 108) * P[i][j-1]

probability = P[0][108]
print(probability)

This code calculates the probability of collecting all 108 coupons after buying 200 boxes. It's important to note that this probability is an approximation, as it relies on recursive and dynamic programming methods. In practice, you might need to purchase more boxes than this estimated value to guarantee the collection of all 108 coupons.

Coupon Collector's Problem: Probability of Collecting All 108 Coupons in 'n' Boxes

原文地址: http://www.cveoy.top/t/topic/nTH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录