QOJ.ac

QOJ

Limite de temps : 8 s Limite de mémoire : 32 MB Points totaux : 100

#16940. 网格

Statistiques

Byteland 的地图绘制在一个大小为 $n \times m$ 的网格上($n$ 是垂直方向的维度,即行数;$m$ 是水平方向的维度,即列数)。划分网格的水平线被称为纬线,从 $0$ 到 $n$ 编号;划分网格的垂直线被称为经线,从 $0$ 到 $m$ 编号(见样例说明中的图)。

天气预报在 Byteland 是一项严肃的任务。对于网格中的每个单位正方形,都需要一定的计算时间来准备预报。由于地形条件和其他因素,这个时间可能因正方形而异。直到最近,预报系统还是一个接一个地处理这些单位正方形,因此准备完整的预报所需的时间等于所有单位时间之和。

你被要求设计一个运行在多处理器计算机上的新系统。为了在处理器之间分配计算,Byteland 的区域应该被 $r$ 条纬线和 $s$ 条经线划分为 $(r + 1)(s + 1)$ 个较小的矩形。每个处理器将负责该划分中的一个矩形,并将一个接一个地处理该矩形内的正方形。这样,一个矩形的计算时间将是该矩形内包含的所有单位正方形的计算时间之和。完整预报的计算时间将是各个处理器计算时间的最大值。

你的任务是选择 $r$ 条纬线和 $s$ 条经线,使得最大计算时间最小。

编写一个程序:

  • 读取 Byteland 地图的尺寸、所需的纬线和经线数量以及单位计算时间;
  • 寻找计算完整预报所需的最小时间;
  • 将得到的值输出。

输入格式

第一行包含四个整数 $n, m, r$ 和 $s$,由单个空格分隔($1 \le r < n \le 18$,$1 \le s < m \le 18$)。

接下来的 $n$ 行包含单位正方形的计算时间。第 $(i + 1)$ 行的第 $j$ 个数字是 $c_{i, j}$ —— 准备位于第 $(i - 1)$ 条和第 $i$ 条纬线之间、以及第 $(j - 1)$ 条和第 $j$ 条经线之间的单位正方形的天气预报所需的时间($1 \le i \le n$,$1 \le j \le m$,$0 \le c_{i, j} \le 2\,000\,000$)。

输出格式

输出恰好一行,包含一个整数 —— 最优的计算时间。

数据范围

对于 $40\%$ 的测试数据,满足 $n$ 和 $m$ 不超过 $10$。

对于 $100\%$ 的数据,满足 $1 \le r < n \le 18$,$1 \le s < m \le 18$,$0 \le c_{i, j} \le 2\,000\,000$。

样例

输入样例 1

7 8 2 1
0 0 2 6 1 1 0 0
1 4 4 4 4 4 3 0
2 4 4 4 4 4 3 0
1 4 4 4 8 4 4 0
0 3 4 4 4 4 4 3
0 1 1 3 4 4 3 0
0 0 0 1 2 1 2 0

输出样例 1

31

说明

第 2 条和第 4 条纬线以及第 4 条经线将国家划分为 6 个矩形,其计算时间分别为 21, 13, 27, 27, 17, 31。完整预报的计算时间为 31。

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.