POJ3422 Kaka's Matrix Travels 【费用流】*

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

Sample Output

15


题意大概就是给你一个n*n的矩形,每一个方格中有一个权值,定义一次行走是从左上角走到右下角,而且每一次移动只能向右边或者下边移动,现在我们要行走k次,并使经过的点集的和最大(每个点值计算一次)

我们很容易想到把每个点的权值作为这个点某种意义上的费用(因为只能计算一次,后面会介绍建图方法),然后我们想最大化这个费用,所以对于这种问题我们可以见图的时候将边权取相反数,然后再跑出最小费用大流的时候将费用取相反数,不难发现这个时候的费用是最大化的

然后我们怎么处理一个节点的边权只能计算一次这个条件呢?
不妨这样思考,我们把一个点i拆成两个点 i i i + n n ,在 i i i + n n 之间连接两条弧:
1:一条容量为1,费用为负边权
2:一条容量为k-1,费用为0
我们可以很容易得到如果有流量经过弧2,一定有流量经过弧1,不然就不满足最小费用的性质
又对于两个节点 i

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值