#abc263f. F - Tournament

F - Tournament

Score : 500500 points

问题描述

2N2^N 名编号为 112N2^N 的人将参加一场剪刀石头布锦标赛。

比赛过程如下:

  • 参赛者按照从左到右的顺序排列成一行,依次为参赛者 11、参赛者 22\ldots、参赛者 2N2^N
  • 设当前行的长度为 2M2M。对于每个 i (1iM)i\ (1\leq i \leq M),从左边数第 (2i1)(2i-1) 位和第 (2i)(2i) 位参赛者进行一场比赛。然后,从行中移除这 MM 名输家。这个过程重复 NN 次。

其中,如果参赛者 ii 赢得了恰好 jj 场比赛,他们将获得 Ci,jC_{i,j} 日元(日本货币)。赢得零场比赛的人不会得到任何奖励。在所有比赛结果都可以自由操纵的情况下,找出这 2N2^N 名参赛者可以获得的最大总金额。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

2N2^N people, numbered 11 to 2N2^N, will participate in a rock-paper-scissors tournament.

The tournament proceeds as follows:

  • The participants are arranged in a row in the order Person 11, Person 22, \ldots, Person 2N2^N from left to right.
  • Let 2M2M be the current length of the row. For each i (1iM)i\ (1\leq i \leq M), the (2i1)(2i-1)-th and (2i)(2i)-th persons from the left play a game against each other. Then, the MM losers are removed from the row. This process is repeated NN times.

Here, if Person ii wins exactly jj games, they receive Ci,jC_{i,j} yen (Japanese currency). A person winning zero games receives nothing. Find the maximum possible total amount of money received by the 2N2^N people if the results of all games can be manipulated freely.

Constraints

  • 1N161 \leq N \leq 16
  • 1Ci,j1091 \leq C_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

C1,1C_{1,1} C1,2C_{1,2} \ldots C1,NC_{1,N}

C2,1C_{2,1} C2,2C_{2,2} \ldots C2,NC_{2,N}

\vdots

C2N,1C_{2^N,1} C2N,2C_{2^N,2} \ldots C2N,NC_{2^N,N}

Output

Print the answer.

Sample Input 1

2
2 5
6 5
2 1
7 9

Sample Output 1

15

The initial row of the people is (1,2,3,4)(1,2,3,4).

If Person 22 wins the game against Person 11, and Person 44 wins the game against Person 33, the row becomes (2,4)(2,4).

Then, if Person 44 wins the game against Person 22, the row becomes (4)(4), and the tournament ends.

Here, Person 22 wins exactly 11 game, and Person 44 wins exactly 22 games, so they receive 0+6+0+9=150+6+0+9=15 yen in total, which is the maximum possible sum.

Sample Input 2

3
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1
1 1 1

Sample Output 2

4

update @ 2024/3/10 11:08:16