Problem2980--【提高】花生采摘

2980: 【提高】花生采摘

[Creator : ]
Time Limit : 1.000 sec  Memory Limit : 128 MiB

Description

鲁宾逊先生有一只宠物猴,名叫多多。这天,他们两个正沿着乡间小路散步,突然发现路边的告示牌上贴着一张小小的纸条:“欢迎免费品尝我种的花生!――熊字”。

鲁宾逊先生和多多都很开心,因为花生正是他们的最爱。在告示牌背后,路边真的有一块花生田,花生植株整齐地排列成矩形网格(如图lns="http://www.w3.org/1998/Math/MathML">1)。有经验的多多一眼就能看出,每棵花生植株下的花生有多少。为了训练多多的算术,鲁宾逊先生说:“你先找出花生最多的植株,去采摘它的花生;然后再找出剩下的植株里花生最多的,去采摘它的花生;依此类推,不过你一定要在我限定的时间内回到路边。”

我们假定多多在每个单位时间内,可以做下列四件事情中的一件:

1) 从路边跳到最靠近路边(即第一行)的某棵花生植株;

2) 从一棵植株跳到前后左右与之相邻的另一棵植株;

3) 采摘一棵植株下的花生;

4) 从最靠近路边(即第一行)的某棵花生植株跳回路边。

现在给定一块花生田的大小和花生的分布,请问在限定时间内,多多最多可以采到多少个花生?注意可能只有部分植株下面长有花生,假设这些植株下的花生个数各不相同。

例如在图2所示的花生田里,只有位于lns="http://www.w3.org/1998/Math/MathML">(2, 5), (3, 7), (4, 2), (5, 4)的植株下长有花生,个数分别为lns="http://www.w3.org/1998/Math/MathML">13, 7, 15, 9。沿着图示的路线,多多在lns="http://www.w3.org/1998/Math/MathML">21个单位时间内,最多可以采到lns="http://www.w3.org/1998/Math/MathML">37个花生。

Tips:在采摘过程中不能回到路边哦。




Input

第一行包括三个整数,lns="http://www.w3.org/1998/Math/MathML">M, Nlns="http://www.w3.org/1998/Math/MathML">K,用空格隔开;表示花生田的大小为lns="http://www.w3.org/1998/Math/MathML">M \times N(1 \le M, N \le 20),多多采花生的限定时间为lns="http://www.w3.org/1998/Math/MathML">K(0 \le K \le 1000)个单位时间。

接下来的lns="http://www.w3.org/1998/Math/MathML">M行,每行包括lns="http://www.w3.org/1998/Math/MathML">N个非负整数,也用空格隔开;

lns="http://www.w3.org/1998/Math/MathML">i + 1行的第lns="http://www.w3.org/1998/Math/MathML">j个整数lns="http://www.w3.org/1998/Math/MathML">Plns="http://www.w3.org/1998/Math/MathML">ij (lns="http://www.w3.org/1998/Math/MathML">0 lns="http://www.w3.org/1998/Math/MathML"> lns="http://www.w3.org/1998/Math/MathML">Plns="http://www.w3.org/1998/Math/MathML">ij lns="http://www.w3.org/1998/Math/MathML"> lns="http://www.w3.org/1998/Math/MathML">500)表示花生田里植株lns="http://www.w3.org/1998/Math/MathML">(i, j)下花生的数目,lns="http://www.w3.org/1998/Math/MathML">0表示该植株下没有花生。

Output

输出包括一行,这一行只包含一个整数,即在限定时间内,多多最多可以采到花生的个数。

Sample Input Copy

6 7 21
0 0 0 0 0 0 0
0 0 0 0 13 0 0
0 0 0 0 0 0 7
0 15 0 0 0 0 0
0 0 0 9 0 0 0
0 0 0 0 0 0 0

Sample Output Copy

37

HINT

样例2:
输入:
6 7 20
0 0 0 0 0 0 0
0 0 0 0 13 0 0
0 0 0 0 0 0 7
0 15 0 0 0 0 0
0 0 0 9 0 0 0
0 0 0 0 0 0 0
输出:
28

Source/Category