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。然後再根據能走的方向向下、右連邊。最後求最大費用流(和最小費用流不同的是,這裏求的是最長路(開始的時候不會出現正圈))

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