QOJ.ac

QOJ

Time Limit: 6 s Memory Limit: 64 MB Total points: 100

#23686. 购物中心

Statistics

在克罗地亚首都萨格勒布,为了配合 IOI 2007 的举办,决定在郊外建设一座大型购物中心。购物中心的建设候选地如下图所示,被划分为横向 $m$ 个街区、纵向 $n$ 个街区的网格状区域。

建设候选地示例 ($m = 10$, $n = 7$)

萨格勒布市决定从建设候选地中选出一个横向 $a$ 个街区、纵向 $b$ 个街区的长方形区域,并在那里建设购物中心。然而,建设候选地内的若干个街区中已经有人居住,无法在这些土地上建设购物中心。如果在一个横向 $a$ 个街区、纵向 $b$ 个街区的长方形区域内没有任何有人居住的街区,则可以通过收购该长方形区域内的所有街区来建设购物中心。

出于萨格勒布市财政上的原因,征地所需的费用需要尽可能少。为了制定预算方案,需要尽快计算出建设购物中心所需的征地费用。因此,萨格勒布市决定委托作为 IOI 2007 代表候选人的你来编写完成这一任务的程序。

当给定建设候选地的大小、购物中心的大小,以及每个街区是否有人居住的信息,和在无人居住时收购该街区所需的费用作为输入时,请编写一个程序,求出建设购物中心所需的征地费用的最小值。

在下文中,将建设候选地中从左数第 $i$ 列、从上数第 $j$ 行的街区记作 $(i, j)$。

输入

输入文件 mall.in 的第 1 行写有两个以空格分隔的整数 $m, n$ ($1 \le m, n \le 1000$)。这表示建设候选地的大小为横向 $m$ 个街区、纵向 $n$ 个街区。

第 2 行写有两个以空格分隔的整数 $a, b$ ($1 \le a, b \le 1000$)。这表示购物中心的大小为横向 $a$ 个街区、纵向 $b$ 个街区。

接下来的 $n$ 行(第 $3$ 行至第 $n + 2$ 行)写有建设候选地内各个街区的信息。第 $j + 2$ 行 ($1 \le j \le n$) 表示从上数第 $j$ 行的街区信息,写有 $m$ 个以空格分隔的整数 $c_{1,j}, \dots, c_{m,j}$ ($-1 \le c_{i,j} \le 100$)。当 $c_{i,j} = -1$ 时,表示街区 $(i, j)$ 有人居住。否则,表示收购街区 $(i, j)$ 所需的费用为 $c_{i,j}$。

此外,对于评测所使用的输入数据,购物中心的建设总是可行的。

输出

请输出到标准输出。输出建设购物中心所需的征地费用的最小值。

样例

输入 1

7 6
3 2
26 29 84 15 -1 1 71
45 14 38 91 62 77 35
68 -1 -1 90 63 56 70
31 2 4 74 72 41 90
100 26 21 -1 44 72 60
71 4 40 93 48 -1 50

输出 1

184

将该输入输出样例中的购物中心建设地用图表示如下。标有 $\times$ 的街区表示已经有人居住。

注意

请注意输入数据的规模。特别是 C++ 的 iostream 较慢,建议根据需要使用 fscanf 等函数。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.