#abc227f. F - Treasure Hunting

F - Treasure Hunting

Score : 500500 points

问题描述

我们有一个具有 HH 行(水平)和 WW 列(垂直)的网格。令 (i,j)(i, j) 表示从上到下第 ii 行、从左到右第 jj 列的方格,其中 (i,j)(i, j) 包含一个整数 Ai,jA_{i,j}

高桥将从起点 (1,1)(1, 1) 出发,并重复向右或向下移动一格,直到到达终点 (H,W)(H, W)。在此过程中,不允许离开网格。

这次旅行的成本定义为:

在经过的 H+W1H+W-1 个方格上书写的整数中最大的 KK 个整数之和。

请找出最小可能的成本。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

We have a grid with HH horizontal rows and WW vertical columns. Let (i,j)(i, j) denote the square at the ii-th row from the top and jj-th column from the left. (i,j)(i, j) contains an integer Ai,jA_{i,j}.

Takahashi will depart (1,1)(1, 1) and repeatedly move one square right or down until reaching (H,W)(H, W). It is not allowed to exit the grid.

The cost of this travel is defined as:

the sum of the KK greatest integers among the integers written on the H+W1H+W-1 squares traversed.

Find the minimum possible cost.

Constraints

  • 1H,W301 \leq H,W \leq 30
  • 1K<H+W1 \leq K < H+W
  • 1Ai,j1091 \leq A_{i,j} \leq 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

HH WW KK

A1,1A_{1,1} A1,2A_{1,2} \ldots A1,WA_{1,W}

A2,1A_{2,1} A2,2A_{2,2} \ldots A2,WA_{2,W}

\vdots

AH,1A_{H,1} AH,2A_{H,2} \ldots AH,WA_{H,W}

Output

Print the answer.

Sample Input 1

1 3 2
3 4 5

Sample Output 1

9

There is only one way to travel, where the traversed squares contain the integers 55, 44, 33 from largest to smallest, so we print 9(=5+4)9(=5+4).

Sample Input 2

2 2 1
3 2
4 3

Sample Output 2

3

The minimum cost is achieved by traversing (1,1)(1,1), (1,2)(1,2), (2,2)(2,2) in this order.

Sample Input 3

3 5 3
4 7 8 6 4
6 7 3 10 2
3 8 1 10 4

Sample Output 3

21

update @ 2024/3/10 09:57:31

}