#graph803. 数字梯形问题
数字梯形问题
Digital Trapezoid Problem
Problem Source
Network Flow 24 Problems
Problem Description
Given a digital trapezoid made of rows of numbers, as shown in the figure below.
2 3
3 4 5
9 10 9 1
1 1 10 1 1
1 1 10 12 1 1
The first row of the trapezoid has numbers. Starting from the numbers at the top of the trapezoid, at each number you may move down-left or down-right, forming a path from the top to the bottom of the trapezoid.
Compute, respectively, under the following three rules:
- The paths from top to bottom are disjoint (no two paths share a vertex).
- The paths from top to bottom may intersect only at number vertices.
- The paths from top to bottom may intersect at number vertices or at edges.
Input Format
The first line contains positive integers , meaning the first row of the trapezoid has numbers and there are rows in total. The following lines are the numbers of each row of the trapezoid.
The first row has numbers, the second row has numbers, and so on.
Output Format
Output the maximum total sum of numbers under rule 1, rule 2, and rule 3, one maximum total per line.
Sample Input
2 5
2 3
3 4 5
9 10 9 1
1 1 10 1 1
1 1 10 12 1 1
Sample Output
66
75
77
Constraints
.
Hint
- All three rules are classic maximum-cost maximum-flow problems on a layered network. Split each cell into an in- and out-node; rule 1 limits each cell to one path (capacity 1 on the out-node), rule 2 allows cell reuse but not edge reuse, and rule 3 allows everything (capacities set to infinity).