Football
Time limit1sMemory limit128 MB
Given pairwise win probabilities, find the team most likely to win a fixed single-elimination bracket of 2^n teams.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Probability, Math
- Solved
- No attempts yet
Problem
Consider a single-elimination football tournament with teams, numbered . In each round, all teams still in the tournament are listed in order of increasing number. Then the first team plays the second, the third plays the fourth, and so on. The winner of each match advances to the next round and the loser is eliminated. After rounds, exactly one undefeated team remains; that team is the champion.
You are given a matrix , where is the probability that team beats team in a single match. Determine which team is most likely to win the tournament.
Input
The input contains several test cases. Each test case begins with a line containing a single integer (). The next lines each contain real numbers; the -th number on the -th line is . The matrix satisfies for all and for all . A line containing a single marks the end of the input.
Every matrix entry is a floating-point number; use double precision to avoid rounding errors.
Output
For each test case, print a single line containing the number of the team most likely to win the tournament. It is guaranteed that the tournament-win probabilities of the two most likely teams differ by at least .
Hint
Consider the four-team example () given by the first test case. In the first round team 1 plays team 2 and team 3 plays team 4; the two winners meet in the final. The probability that team 2 wins the tournament is
The next most likely champion is team 3, with probability .