#P2774. 方格取数问题

    ID: 1779 远端评测题 1000ms 125MiB 尝试: 6 已通过: 1 难度: 8 上传者: 标签>网络流O2优化深度优先搜索,DFS最大流最小割网络流 24 题

方格取数问题

Description

There is an mm-row nn-column grid, with a positive integer in each cell. You need to pick numbers from the grid so that no two chosen cells share a common edge, and the total sum of the chosen numbers is maximized. Please compute the maximum possible sum.

Input Format

The first line contains two integers separated by a space, representing the number of rows mm and the number of columns nn.

From line 22 to line (m+1)(m + 1), each line contains nn integers. The jj-th integer on line (i+1)(i + 1) represents the number in the cell at row ii, column jj, namely ai,ja_{i, j}.

Output Format

Output a single integer on one line, representing the maximum sum.

3 3
1 2 3
3 2 3
2 3 1 
11

Hint

Constraints

For 100%100\% of the testdata, it is guaranteed that 1n,m1001 \leq n, m \leq 100, 1ai,j1051 \leq a_{i, j} \leq 10^5.

Tip

Please note that in the first line, mm is read before nn.

Translated by ChatGPT 5