算法题:UVA 10913 Walking on a Grid(记忆化搜索)2014-04-10 csdn accelerator_

You will be given a square grid of size
N × N. The top-left square has a coordinate of (1, 1) and that of bottom-right is (
N, N). Your job is to walk from
(1, 1) to
(N, N).Very easy, right? That’s why you have to follow some rules when walking.You can only move left, right or down.(i, j-1) is left of (i, j), (i, j+1) is right of (i, j) and (i+1, j) is down of (i, j).You can never move outside the grid.You can not step on a cell more than once.Every cell has an integer associated with it.You have to make sure the sum of integers of the path is maximized.You can step on at most
k negative integers from source to destination.
InputEach case will start with two integers
N and
k.
N ≤ 75 and
k ≤ 5. Each of the next
N lines will contain
N integers each given in row major order. That is, the first integer of the first row is (1, 1) and the last integer of last row is (
N, N). Input terminates with two zeros on a line.
OutputFor every case output the case number. If it’s not possible to reach the destination meeting the above rules then output “impossible”, else print the maximum sum of integers of the path.