#P1004. [NOIP 2000 提高组] 方格取数

    ID: 4 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>动态规划,dp2000递归NOIp 提高组费用流

[NOIP 2000 提高组] 方格取数

Description

Consider an N×NN \times N grid (N9N \le 9). Some cells are filled with positive integers, while the others contain the number 00. As shown below (see the sample):

A person starts from the top-left corner point AA, and may move either down or right until reaching the bottom-right corner point BB. Along the way, he may collect the numbers in the cells he visits (after which those cells become the number 00).
This person travels from AA to BB twice. Find two such paths that maximize the total sum collected.

Input Format

The first line contains an integer NN (the size of the N×NN \times N grid). Each subsequent line contains three integers: the first two specify a position, and the third is the number placed at that position. A line containing 0 0 00\ 0\ 0 indicates the end of input.

Output Format

Output a single integer, the maximum total collected along the two paths.

8
2 3 13
2 6  6
3 5  7
4 4 14
5 2 21
5 6  4
6 3 15
7 2 14
0 0  0

67

Hint

Constraints: 1N91 \le N \le 9.

Translated by ChatGPT 5