PROBLEM SYNOPSIS
----------------

Given a number of players and their ratings (indicating their strength), find the way to set up a knock-out tournament that maximizes the probability of winning the tournament for a given player. Compute that probability.


KEYWORDS
--------

Probabilities, Greedy, DP


ESTIMATED DIFFICULTY LEVEL
--------------------------

30


SOLUTION
--------

The ideal way to distribute the players is to put the strongest players in the same half. This holds for all "subtrees" as well. The target player is treated as if he were the weakest player. Thus, in a standard schematic of a knock-out tournament, the players are put down in order of strength, with the target player in the role of the lowest rated one.
That this is optimal can be understood as follows: any deviation from the above improves the odds of all the players belonging to the strongest half, and reduces them for the weakest half. This is always bad news for the target player.
The byes can be treated as players with rating 0, although they must not be paired in the first round. Instead, they are paired to the weakest players (and the target player).

The probability of winning the tournament can be calculated by progressing through the rounds and, for every player, keeping track of the probability that they reach that stage. The probability of advancing a round further is simply the old probability multiplied by the following sum: for each possible opponent, the probability of him having advanced to that stage, multiplied by the probability of beating him.


COMPLEXITY
----------

n <= 1024
Memory: O(n*log(n))
Time: O(n^2) (in calculating the probabilities, every possible match-up is considered (at most) once.)
