Tap here to switch tabs
Problem
Ask
Submissions

Problem: Soup Servings

med
30 min
Explore how to apply dynamic programming to calculate the probability that soup A becomes empty before soup B in a random serving process. Understand the problem constraints and develop a solution using efficient probability computation methods.

Statement

You begin with two types of soup, A and B, each containing n milliliters. During each turn, exactly one of the following four operations is selected uniformly at random (each with probability 0.250.25), independent of all prior turns:

  • Serve 100100 mL of soup A and 00 mL of soup B.

  • Serve 7575 mL of soup A and 2525 mL of soup B.

  • Serve 5050 mL of soup A and 5050 mL of soup B.

  • Serve 2525 mL of soup A and 7575 mL of soup B.

The serving from both soups happens simultaneously in each turn. If an operation requires serving more than the remaining amount of a particular soup, simply serve whatever is left of that soup. The process terminates immediately after any turn in which at least one soup becomes empty.

Compute and return the probability that soup A becomes empty before soup B, plus half the probability that both soups become empty at the same time. Answers within 10510^{-5} of the true value will be accepted.

Note: There is no operation that serves 00 mL of soup A and 100100 mL of soup B.

Constraints:

  • 00 \leq n 109\leq 10^9

Tap here to switch tabs
Problem
Ask
Submissions

Problem: Soup Servings

med
30 min
Explore how to apply dynamic programming to calculate the probability that soup A becomes empty before soup B in a random serving process. Understand the problem constraints and develop a solution using efficient probability computation methods.

Statement

You begin with two types of soup, A and B, each containing n milliliters. During each turn, exactly one of the following four operations is selected uniformly at random (each with probability 0.250.25), independent of all prior turns:

  • Serve 100100 mL of soup A and 00 mL of soup B.

  • Serve 7575 mL of soup A and 2525 mL of soup B.

  • Serve 5050 mL of soup A and 5050 mL of soup B.

  • Serve 2525 mL of soup A and 7575 mL of soup B.

The serving from both soups happens simultaneously in each turn. If an operation requires serving more than the remaining amount of a particular soup, simply serve whatever is left of that soup. The process terminates immediately after any turn in which at least one soup becomes empty.

Compute and return the probability that soup A becomes empty before soup B, plus half the probability that both soups become empty at the same time. Answers within 10510^{-5} of the true value will be accepted.

Note: There is no operation that serves 00 mL of soup A and 100100 mL of soup B.

Constraints:

  • 00 \leq n 109\leq 10^9