#P2045. 方格取数加强版

方格取数加强版

Description

Given an n×nn \times n matrix. Each cell contains a non-negative integer Ai,jA_{i,j} (Ai,j103A_{i,j} \le 10^3). Starting from (1,1)(1, 1), you may move only right or down and finally reach (n,n)(n, n). Every time you arrive at a cell, you take the number in that cell and the cell’s value becomes 00. Repeat this walk a total of KK times. Find the maximum possible sum of the values collected over the KK walks.

Input Format

The first line contains two integers n,Kn, K (1n501 \le n \le 50, 0K100 \le K \le 10).

The next nn lines each contain nn integers, denoting the value of each cell in the matrix.

Output Format

Output a single integer, the maximum sum.

3 1
1 2 3
0 2 1
1 4 2
11

Hint

The value in each cell does not exceed 10001000.

Translated by ChatGPT 5