pku 3422 最大费用流

                                                       Kaka's Matrix Travels
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 4717 Accepted: 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。然后再根据能走的方向向下、右连边。最后求最大费用流(和最小费用流不同的是,这里求的是最长路(开始的时候不会出现正圈))

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章