QOJ.ac

QOJ

時間限制: 1.0 s 記憶體限制: 2048 MB 總分: 100

#16826. 办公楼

统计

Z 公司为他们的新办公大楼购买了一块土地。这块土地呈长方形网格状,有 $r$ 行和 $c$ 列,每个网格中都有一棵树。每棵树的树龄都是已知的。

由于 Z 公司处于世界创新的前沿,他们的新办公大楼将不仅仅是矩形的。相反,它将具有某种奇特的外形和非常特殊的平面图。该形状可以用一些连通的网格单元来表示。大楼没有特定的朝向要求,平面图可以旋转 90 度的任意倍数。但是,平面图不能进行水平或垂直翻转。

Z 公司希望在他们的土地内选择一个建楼位置。被大楼占用的网格单元中的树木必须被砍倒。Z 公司希望保留树木,使得剩余树木的树龄之和尽可能大。你能帮他们选择新办公大楼的最佳位置吗?

输入格式

输入的第一行包含两个整数 $r$ 和 $c$($1 \le r, c \le 20$),表示土地的尺寸。

接下来的 $r$ 行,每行包含 $c$ 个介于 1 到 100 之间(均包含)的整数,描述土地中树木的树龄。

下一行包含两个整数 $s$ 和 $t$($1 \le s \le r, 1 \le t \le c$),表示大楼平面图的尺寸。

接下来的 $s$ 行,每行包含 $t$ 个字符,描述大楼的平面图。井号(#)表示被大楼占用的单元格,点号(.)表示未被占用的单元格。平面图中至少有一个井号。保证井号构成一个连通的形状。如果两个井号所在的单元格共享一条边,则它们是直接相连的;当一个形状中的所有井号都直接或间接相连时,该形状是连通的。平面图中不存在完全为空的行或列。

输出格式

输出一个整数,表示可以保留的树木的最大树龄之和。

样例

输入样例 1

4 5
4 3 1 1 1
5 4 3 5 1
9 6 2 1 1
8 7 1 1 2
3 4
###.
#.##
#..#

输出样例 1

58

输入样例 2

3 3
6 6 6
3 6 1
1 1 1
2 3
#..
###

输出样例 2

25

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.