题目描述
Problem Description
You have a matrix of $H$ rows and $W$ columns. The element at the $i$-th row and $j$-th column is a single-digit positive integer $S_{i, j}$.
You can perform the following two types of operations in any order, up to a total of $H + W - 2$ times:
- Select two adjacent rows ($i$-th and $i + 1$-th rows), gain the sum of the elements in these two rows as points, and then compress these two rows. That is, replace the entire matrix with the concatenation of (if they exist) the rows before the $i$-th row, the sum of the $i$-th and $i + 1$-th rows as a row vector, and (if they exist) the rows after the $i + 1$-th row, in this order vertically. This operation can be performed if the matrix has at least two rows.
- Select two adjacent columns ($j$-th and $j + 1$-th columns), gain the sum of the elements in these two columns as points, and then compress these two columns. That is, replace the entire matrix with the concatenation of (if they exist) the columns before the $j$-th column, the sum of the $j$-th and $j + 1$-th columns as a column vector, and (if they exist) the columns after the $j + 1$-th column, in this order horizontally. This operation can be performed if the matrix has at least two columns.
Find the maximum possible total score that can be obtained.
Input Format
The input is given from the standard input in the following format:
$H$ $W$ $S_{1, 1}S_{1, 2}\ldots S_{1, W}$ $S_{2, 1}S_{2, 2}\ldots S_{2, W}$ $\vdots$ $S_{H, 1}S_{H, 2}\ldots S_{H, W}$
Output Format
Output the maximum possible total score that can be obtained.
Sample Input and Output
Sample Input #1
3 3
314
159
265
Sample Output #1
130
Sample Input #2
10 8
82974679
74744362
34499984
86891758
56419363
76176864
78392791
71539599
44588446
71227999
Sample Output #2
4555
Notes/Hints
Constraints
- All inputs are integers.
- $1 \le H, W \le 3000$
- $1 \le S_{i, j} \le 9$
Partial Points
- If you solve the dataset where $1 \leq H, W \leq 200$, you will be awarded 30 points.
Sample Explanation 1
One of the optimal ways is to choose the $2, 3$-th columns, $2, 3$-th rows, $1, 2$-th rows, and $1, 2$-th columns in order. This way, you can obtain $30 + 28 + 36 + 36 = 130$ points. The matrix changes as follows:
\[ \begin{bmatrix} 3 & 1 & 4 \\ 1 & 5 & 9 \\ 2 & 6 & 5 \end{bmatrix} \to \begin{bmatrix} 3 & 5 \\ 1 & 14 \\ 2 & 11 \end{bmatrix} \to \begin{bmatrix} 3 & 5 \\ 3 & 25 \end{bmatrix} \to \begin{bmatrix} 6 & 30 \end{bmatrix} \to \begin{bmatrix} 36 \end{bmatrix} \]
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分