#P4190. [CTSC2010] 三国围棋擂台赛

[CTSC2010] 三国围棋擂台赛

Description

The annual “Nongshim Cup” three-nation Go relay tournament is the highest-level Go competition in the world and the most exciting contest among China, Japan, and Korea. This problem is based on the rules of that event.

The three-nation Go relay tournament is a match among national teams of three countries. The rules are briefly as follows:

  1. Let the three countries be AA, BB, and CC. Each country has nn players (in the real event above, n=5n = 5), named A1,A2,,AnA_1, A_2, \ldots, A_n, B1,B2,,BnB_1, B_2, \ldots, B_n, and C1,C2,,CnC_1, C_2, \ldots, C_n.

  2. Every game has a winner and a loser. The loser of a game is eliminated.

  3. The first player to appear for each team is fixed to be that team’s nn-th player, i.e., AnA_n, BnB_n, and CnC_n.

  4. One team is drawn uniformly at random. That team has a bye in round 1, and the nn-th players of the other two teams play the first game.

  5. The winner of the first game (the “winner” here always means the player who wins that game) plays the nn-th player of the team that had the bye in the second game. For example, if CnC_n defeats AnA_n in the first game, then the second game is CnC_n vs. BnB_n.

  6. From the third game onward, the team that did not participate in the previous game selects one not-yet-eliminated player to play against the previous game’s winner.

  7. This process continues until all players of some team have been eliminated.

  8. When only two teams remain, after each game, the losing side chooses one not-yet-eliminated player to play the next game against the winner.

  9. When all players of either of the two remaining teams are eliminated, the match ends, and the remaining team wins the Nongshim Cup.

A new edition of the tournament is about to begin. As the leader of Team AA, you have computed the win probabilities among all 3n3n players — that is, for any two players QQ and RR from different teams, we know that the probability that QQ defeats RR is pp (0p10 \leq p \leq 1), and the probability that RR defeats QQ is 1p1 - p.

Since your country is overwhelmingly strong, assume the other two teams will both target you. Every decision by Teams BB and CC — i.e., the order in which they send players — aims to minimize the probability that Team AA wins the title, while Team AA’s decisions aim to maximize that probability. Your task is to compute, under this highly unfavorable scenario and assuming all three sides play optimally, the expected probability EAE_A that Team AA wins the championship.

About the expectation: suppose the current game is between players QQ and RR, and QQ defeats RR with probability pp. Then Team AA’s winning expectation at this moment is EA=p×E1+(1p)×E2E_A = p \times E_1 + (1 - p) \times E_2, where E1E_1 is the expectation that Team AA wins the title after QQ defeats RR, and E2E_2 is the expectation after RR defeats QQ. E1E_1 and E2E_2 are computed recursively using the same formula.

Team AA’s decisions will maximize this expectation, while Teams BB and CC will minimize it. If all players of Teams BB and CC are eliminated, the expectation is 11; if all players of Team AA are eliminated, the expectation is 00.

For example, when each team has 33 players, the head-to-head win probabilities are given by the following three 3×33\times 3 matrices. In each matrix, every value pp is the row player’s probability of defeating the column player, and the column player’s probability of defeating the row player is 1p1 - p.

The third players of the three teams are of equal strength. After the first two games, the probability that the current winner comes from any of the three teams is the same. Suppose the winner of the second game is B3B_3, and in the third game it is Team AA’s turn to send a player. Team AA can choose between A1A_1 and A2A_2.

If we send A2A_2, although the third game is guaranteed to defeat B3B_3 (win probability 100%100 \%), Team CC will send C2C_2 in the fourth game, against whom A2A_2 surely loses (win probability 00). In the fifth game, Team BB will send B1B_1, and in the sixth game only A1A_1 can be sent. Since B2B_2, who surely defeats A1A_1, has not yet appeared, A1A_1 will be eliminated sooner or later, and Team AA’s winning probability is 00.

If we send A1A_1, although the win probability against B3B_3 in this game is only 50%50 \%, the probability of winning the championship is 6.25%6.25 \%. Therefore, in the third game we should send A1A_1.

Considering the six possible pairs of players in the third game, the final expected championship probability is:

$$\dfrac{(6.25\%+3.125\%+18.75\%+25\%+60.9375\%+50\%)}{6} = 27.34375\%.$$

Input Format

The input file is go.in.

The first line contains an integer nn, the number of players on each team.

Lines 22 to n+1n + 1 each contain nn real numbers, forming an n×nn \times n matrix that gives Team AA’s win probabilities against Team BB. In particular, on line i+1i + 1, the jj-th number is the probability that player AiA_i defeats player BjB_j.

Line n+2n + 2 is a blank line.

Lines n+3n + 3 to 2n+22n + 2 each contain nn real numbers, forming an n×nn \times n matrix that gives Team AA’s win probabilities against Team CC. In particular, on line i+n+2i + n + 2, the jj-th number is the probability that player AiA_i defeats player CjC_j.

Line 2n+32n + 3 is a blank line.

Lines 2n+42n + 4 to 3n+33n + 3 each contain nn real numbers, forming an n×nn \times n matrix that gives Team BB’s win probabilities against Team CC. In particular, on line i+2n+3i + 2n + 3, the jj-th number is the probability that player BiB_i defeats player CjC_j.

Output Format

The output file go.out contains a single real number with 66 decimal places, the probability that Team AA wins the championship.

3
1.0 0.0 0.5
0.5 1.0 1.0
0.5 0.5 0.5

0.5 0.5 1.0
0.5 0.0 0.5
0.5 0.5 0.5

0.5 0.0 1.0
0.5 0.5 0.5
0.5 0.5 0.5 

0.273438

Hint

  • For 30%30\% of the testdata, n4n \leq 4.
  • For 40%40\% of the testdata, n5n \leq 5.
  • For 100%100\% of the testdata, n7n \leq 7.
  • For 10%10\% of the testdata, in each of the three win-probability matrices, every matrix has constant entries (all elements in a given matrix are the same), but different matrices may have different values.

Translated by ChatGPT 5