CF48B.Land Lot

普及-

通过率:0%

时间限制:2.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Vasya has a beautiful garden where wonderful fruit trees grow and yield fantastic harvest every year. But lately thieves started to sneak into the garden at nights and steal the fruit too often. Vasya can’t spend the nights in the garden and guard the fruit because there’s no house in the garden! Vasya had been saving in for some time and finally he decided to build the house. The rest is simple: he should choose in which part of the garden to build the house. In the evening he sat at his table and drew the garden’s plan. On the plan the garden is represented as a rectangular checkered field n × m in size divided into squares whose side length is 1. In some squares Vasya marked the trees growing there (one shouldn’t plant the trees too close to each other that’s why one square contains no more than one tree). Vasya wants to find a rectangular land lot a × b squares in size to build a house on, at that the land lot border should go along the lines of the grid that separates the squares. All the trees that grow on the building lot will have to be chopped off. Vasya loves his garden very much, so help him choose the building land lot location so that the number of chopped trees would be as little as possible.

瓦西娅有一座美丽的花园,园中生长着奇妙的果树,每年都能收获丰硕的果实。但最近小偷们开始频繁在夜间潜入花园偷窃水果。由于花园里没有房屋,瓦西娅无法整夜待在花园中看守果实!瓦西娅已为此储蓄了一段时间,最终决定建造一座房屋。接下来的事情很简单:他需要选择在花园的哪个位置建造房屋。傍晚时分,他坐在桌旁,画出了花园的平面图。在该平面图中,花园被表示为一个 n×mn \times m 的矩形方格网格,每个方格边长为 1。在某些方格中,瓦西娅标出了生长在那里的果树(由于果树不宜种植得过于靠近,因此每个方格至多只有一棵果树)。瓦西娅希望选定一块大小为 a×ba \times b 个方格的矩形地块来建造房屋,且该地块的边界必须与分割方格的网格线重合。所有生长在该建筑地块上的果树都将被砍伐。瓦西娅非常热爱自己的花园,因此请帮助他选择建筑地块的位置,使得被砍伐的果树数量尽可能少。

输入格式

The first line contains two integers n and m (1 ≤ n, m ≤ 50) which represent the garden location. The next n lines contain m numbers 0 or 1, which describe the garden on the scheme. The zero means that a tree doesn’t grow on this square and the 1 means that there is a growing tree. The last line contains two integers a and b (1 ≤ a, b ≤ 50). Note that Vasya can choose for building an a × b rectangle as well a b × a one, i.e. the side of the lot with the length of a can be located as parallel to the garden side with the length of n, as well as parallel to the garden side with the length of m.

第一行包含两个整数 nn 和 mm(1≤n,m≤501 \leq n, m \leq 50),表示花园的尺寸。接下来的 nn 行,每行包含 mm 个数字(00 或 11),描述花园的布局:00 表示该位置没有树,11 表示该位置有一棵树。最后一行包含两个整数 aa 和 bb(1≤a,b≤501 \leq a, b \leq 50)。注意,瓦夏在建造矩形地块时,既可以选择 a×ba \times b 的矩形,也可以选择 b×ab \times a 的矩形;即长度为 aa 的边既可以与长度为 nn 的花园边平行,也可以与长度为 mm 的花园边平行。

输出格式

Print the minimum number of trees that needs to be chopped off to select a land lot a × b in size to build a house on. It is guaranteed that at least one lot location can always be found, i. e. either a ≤ n and b ≤ m, or a ≤ m и b ≤ n.

输出为建造一座房屋而需砍伐的最少树木数量,以便选出一块大小为 a×ba \times b 的地块。题目保证总能找到至少一个符合条件的地块位置,即满足 a≤na \leq n 且 b≤mb \leq m,或 a≤ma \leq m 且 b≤nb \leq n。

输入输出样例

  • 输入#1

    2 2
    1 0
    1 1
    1 1

    输出#1

    0
  • 输入#2

    4 5
    0 0 1 0 1
    0 1 1 1 0
    1 0 1 0 1
    1 1 1 1 1
    2 3

    输出#2

    2

说明/提示

In the second example the upper left square is (1,1) and the lower right is (3,2).

在第二个例子中,左上角的方格是 (1,1)(1,1),右下角的方格是 (3,2)(3,2)。

输入解题思路,AI测评打分。不知道怎么写?

首页