pku 3422 最大费用流

本文讨论了在给定矩阵中,从左上角到右下角的路径中,通过特定移动规则,如何最大化路径上数字的累加和,并在经过K次移动后达到的最大和。涉及算法设计和路径优化。
                                                       Kaka's Matrix Travels
Time Limit: 1000MSMemory Limit: 65536K
Total Submissions: 4717Accepted: 1834

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 2
1 2 3
0 2 1
1 4 2

Sample Output

15

Source

POJ Monthly--2007.10.06 , Huang, Jinsong

 

一个矩阵,一个人只能往下或右走一格,一次从左上角走到右下角所得的价值是走过的格子的权值和,走过后这个格子中的权值边为0。现在走k次,问你能得到的最大价值?

对于每个格子拆点,设为 u , u'  则连两条边 u--->u' 容量为1,费用为权值和 u----->u' ,容量为k-1,费用为0。然后再根据能走的方向向下、右连边。最后求最大费用流(和最小费用流不同的是,这里求的是最长路(开始的时候不会出现正圈))

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值