#T510. 【NOIP2008-S3】传纸条

【NOIP2008-S3】传纸条

Description

Xiao Yuan and Xiao Xuan are good friends and classmates who always have endless topics to discuss. During a team-building activity, their classmates were arranged into a matrix with m rows and n columns, while Xiao Yuan and Xiao Xuan were placed at opposite ends of the matrix's diagonal, making direct conversation impossible. Fortunately, they could communicate by passing notes. The notes must pass through many classmates to reach the other person. Xiao Yuan sits at the top-left corner of the matrix, coordinates (1, 1), and Xiao Xuan sits at the bottom-right corner, coordinates (m, n). Notes passed from Xiao Yuan to Xiao Xuan can only move downward or to the right, while notes passed from Xiao Xuan to Xiao Yuan can only move upward or to the left.

During the activity, Xiao Yuan wants to send a note to Xiao Xuan and also hopes to receive a reply from Xiao Xuan. Each classmate can help them pass the note, but only once. That is, if a classmate helps when Xiao Yuan sends a note to Xiao Xuan, they will not help again when Xiao Xuan sends a note back to Xiao Yuan, and vice versa.

Another thing to note is that each classmate has a varying level of willingness to help (note: the willingness levels of Xiao Yuan and Xiao Xuan are undefined and represented as 0 in the input), which can be represented by a natural number between 0 and 100. The higher the number, the more willing the classmate is to help. Xiao Yuan and Xiao Xuan want to find classmates with the highest willingness levels to pass the notes, i.e., to find two round-trip paths such that the sum of the willingness levels of the classmates on these paths is maximized. Now, please help Xiao Yuan and Xiao Xuan find such two paths.

Input Format

The first line contains two integers m and n separated by a space, indicating that the class has m rows and n columns (1 ≤ m, n ≤ 50).

The next m lines form an m × n matrix, where the integer at the i-th row and j-th column represents the willingness level of the student sitting at that position. The n integers in each row are separated by spaces.

Output Format

Output a single line containing an integer, representing the maximum sum of the willingness levels of the classmates involved in passing the notes along the two round-trip paths.

```input1 3 3 0 3 9 2 8 5 5 7 0 ``` ```output1 34 ``` ## Source

NOIP2008-S3