A8057 | Land Lot
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
输入格式
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$ .
输出格式
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$ .
输入输出样例
输入 #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).
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted