POJ 3422 Kaka's Matrix Travels (最小费用流)
Description
On an N × N chessboard with a non-negative number in each grid, Kaka starts his matrix travels with SUM = 0. For each travel, Kaka moves one rook from the left-upper grid to the right-bottom one, taking care that the rook moves only to the right or down. Kaka adds the number to SUM in each grid the rook visited, and replaces it with zero. It is not difficult to know the maximum SUM Kaka can obtain for his first travel. Now Kaka is wondering what is the maximum SUM he can obtain after his Kth travel. Note the SUM is accumulative during the K travels.
Input
The first line contains two integers N and K (1 ≤ N ≤ 50, 0 ≤ K ≤ 10) described above. The following N lines represents the matrix. You can assume the numbers in the matrix are no more than 1000.
Output
The maximum SUM Kaka can obtain after his Kth travel.
Sample Input
3 21 2 30 2 11 4 2
Sample Output
15
题意
给出一个 N∗N
思路
和 HDU 3376 一样的题型,只不过 HDU 3376 里面规定只有两条路径,而这里规定有 k 条,然后在建图策略中只需要修改原来矩阵中点到扩充点费用为0的边的容量为k-1即可。
具体请看:HDU 3376 Matrix Again
AC 代码
#include#include#include#include#include#includeusing namespace std;#include#include
暂时没有评论,来抢沙发吧~