Football corruption

An infamous football club (let us call it X) wants to buy yet another
competition. There are n teams, where n = 2^(m) for some m. As usual,
the tournament scheme is a complete binary tree, so X will have to win m
matches to be the champion. The president of X knows, for every pair of
teams i and j, the probability p_(ij) that i eliminates j. So he will
bribe the football federation, and arrange the play offs so as to
maximize the probability that X wins the competition. Can you compute
that probability?

Input

Input consists of several cases, each one with n, followed by n lines
with n probabilities each, where the j-th number of the i-th line is
p_(ij). Assume 1 ≤ m ≤ 3, that p_(ji) = 1 − p_(ij) for every i ≠ j, and
that the diagonal of the matrix has only -1. X is the first team.

Output

For every case, print the probability with four digits after the decimal
point. The input cases have no precission issues.

Hint

The expected solution is a “reasonable” backtracking. For instance, 2000
tests with n = 8 should be solved in at most one second.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T12:00:57.487Z

© Jutge.org, 2006–2026.
https://jutge.org
