#P1005. [NOIP 2007 提高组] 矩阵取数游戏
[NOIP 2007 提高组] 矩阵取数游戏
Description
Shuai Shuai often plays a matrix number picking game with classmates: given an matrix where each element is a non-negative integer, the game rules are as follows:
- In each round, exactly one element is taken from each row, for a total of elements. After rounds, all elements in the matrix are taken.
- Each taken element must be either the leftmost or the rightmost element of its row.
- The score of each round is the sum of the per-row scores. The per-row score equals the value of the taken element , where denotes the -th round (starting from ).
- The total score of the game is the sum of the scores over all rounds.
Please write a program that, for any given matrix, computes the maximum possible total score.
Input Format
The input consists of lines.
- The first line contains two integers and separated by a space.
- Lines to contain the matrix. Each line has non-negative integers separated by single spaces.
Output Format
Output a single line containing one integer: the maximum possible total score.
2 3
1 2 3
3 4 2
82
Hint
- Constraints:
- For of the testdata, , and the answer does not exceed .
- For of the testdata, , .
- Source: NOIP 2007 Senior, Problem 3.
Translated by ChatGPT 5
京公网安备 11011102002149号