Dynamic Programming21 sections · 916 units
Open in Course

LeetCode 808 Soup Servings - The Observation

Scaling trick

State is (a,b)(a, b) = remaining amounts of soup A and B. But if n=109n = 10^9, that's way too many states. observation: all serving amounts are multiples of 2525. Divide everything by 2525.

State becomes (a/25,b/25)(a/25, b/25). Another observation: soup A is served more on average (100+75+50+25)/4 = 62.5 vs (0+25+50+75)/4 = 37.5. For large nn, A almost certainly empties first. When n>4800n > 4800, the probability is so close to 11 that the difference is below 10510^{-5} (the required precision). Return 1.01.0 directly for large nn.