#P7266. [BalticOI 2000] Honeycomb Problem

    ID: 7510 远端评测题 1000ms 128MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>动态规划 DP2000BalticOI(波罗的海)

[BalticOI 2000] Honeycomb Problem

Problem Description

As shown in the figure below, this is a honeycomb graph with side length 33, and each point has a weight:

Now you need to go from some point in the top row to some point in the bottom row. Each move can only go to the lower-left point or the lower-right point. You may swap the values of two points in at most one selected row.

Find the maximum possible sum of point weights along a path from the top row to the bottom row after performing the swap.

Input Format

The first line contains an integer nn, representing the side length of the honeycomb graph.
The next 2n12n-1 lines contain several integers per line, describing the honeycomb graph.

Output Format

Output one integer on one line, representing the answer.

3
1 2 3
3 2 2 1
4 2 8 0 3
5 3 1 2
3 1 4
22

Hint

Sample Explanation

For sample 11, swap 55 and 11 in the fourth row, and then we can obtain a path with the maximum sum of point weights:

328543 \to 2 \to 8 \to 5 \to 4

The maximum value is 2222.

Constraints

For 100%100\% of the testdata, 1n991 \le n \le 99, and 00 \le each value in the honeycomb graph 99\le 99.

Note

Translated from BalticOI 2000 Day1 A Honeycomb Problem

Translated by ChatGPT 5