#P1004. [NOIP 2000 提高组] 方格取数
[NOIP 2000 提高组] 方格取数
Description
Consider an grid (). Some cells are filled with positive integers, while the others contain the number . As shown below (see the sample):

A person starts from the top-left corner point , and may move either down or right until reaching the bottom-right corner point . Along the way, he may collect the numbers in the cells he visits (after which those cells become the number ).
This person travels from to twice. Find two such paths that maximize the total sum collected.
Input Format
The first line contains an integer (the size of the 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 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: .
Translated by ChatGPT 5
京公网安备 11011102002149号