Given N supporters of A and M of B, find the probability that A leads after every vote in a random arrival order.
Easy3MathProbabilityCombinatoricsNo attempts yetTime limit5sMemory limit512 MBA and B are the only two candidates in an election. Polls show that exactly N voters support A and exactly M voters support B. Since N is greater than M, A wins the election.
Voters arrive at the polling place one at a time. The arrival order is chosen uniformly at random among all (N+M)! possible orders. After each vote, the polling place worker updates the running count and writes down which candidate is ahead at that moment. If the two counts are equal, no candidate is ahead.
Compute the probability that A is ahead after every single vote, from the first one to the last.
The first line contains the number of test cases T. Each test case is one line with two integers N and M, the number of voters supporting A and the number supporting B.
For each test case, print one line in the form Case #x: y. Here x is the test case number, starting from 1, and y is the probability that A is ahead after every vote.
Print y rounded to exactly eight digits after the decimal point, padding with zeros when needed. For example, a probability of 1 is printed as 1.00000000.
Take N=2 and M=1. Call the supporters of A A1 and A2, and the supporter of B just B. The six possible arrival orders are A1 A2 B, A2 A1 B, A1 B A2, A2 B A1, B A1 A2, B A2 A1. Only the first two keep A ahead after every vote. With the order A1 B A2, A is ahead after the first vote but the count is tied after the second one. The answer is 2/6=0.33333333…
With N=1 and M=0 there is a single voter, and that voter supports A. Only one order exists, and A is ahead after that one vote.