A1384 | [COCI-2020-2021-contest3]#3 Selotejp
来源COCI
时间限制1s
内存限制128MB
通过 / 提交0/0
题目描述
For Mirko there is no greater happiness than finding a new roll of sticky tape, and today he is especially happy because he had also found Slavko’s Advent calendar.
The Advent calendar can be represented as a table with n rows and m columns. Each square contains a little window, and behind each window is a piece of chocolate. Slavko had already opened some of the windows, and others are still closed.
Mirko decided to use his sticky tape to glue all closed windows shut. The tape is infinitely long, and it is one calendar cell wide. Mirko can rip off a piece of tape and use it to glue some sequence of horizontally or vertically adjacent closed windows shut. He doesn’t want to put more than one piece of tape over some window, since he wants to remain friends with Slavko.
He is wondering what is the minimal number of pieces of tape he needs to glue all closed windows shut.
The Advent calendar can be represented as a table with n rows and m columns. Each square contains a little window, and behind each window is a piece of chocolate. Slavko had already opened some of the windows, and others are still closed.
Mirko decided to use his sticky tape to glue all closed windows shut. The tape is infinitely long, and it is one calendar cell wide. Mirko can rip off a piece of tape and use it to glue some sequence of horizontally or vertically adjacent closed windows shut. He doesn’t want to put more than one piece of tape over some window, since he wants to remain friends with Slavko.
He is wondering what is the minimal number of pieces of tape he needs to glue all closed windows shut.
输入格式
The first line contains integers n and m (1 ≤ n ≤ 1000, 1 ≤ m ≤ 10), dimensions of the Advent calendar.
Each of the following n lines contains m characters ’.’ and ’#’ that represent the Advent calendar. The character ’.’ denotes an open window, and the character ’#’ denotes a closed window.
Each of the following n lines contains m characters ’.’ and ’#’ that represent the Advent calendar. The character ’.’ denotes an open window, and the character ’#’ denotes a closed window.
输出格式
Output the minimal number of pieces of tape needed to glue all closed windows shut.
输入输出样例
输入 #1
2 3 #.# ###
输出 #1
3
输入 #2
4 3 .#. ### .## .#.
输出 #2
3
Clarification of the first example:
One possible solution is to use one piece of tape for the first column, one piece for the third column, and
one piece for the window in the second row and second column.
One possible solution is to use one piece of tape for the first column, one piece for the third column, and
one piece for the window in the second row and second column.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted