After scaling by , define = probability that A empties first (plus half of both empty) given units of A and units of B remain. Base cases:
If and : both empty simultaneously. Return .
If : A emptied first. Return .
If : B emptied first. Return . The answer is , rounded up if not divisible. This dp definition has all the information needed to compute the probability from (a, b).