CF1404E.Bricks
省选/NOI-
通过率:0%
时间限制:4.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
A brick is defined as a rectangle with integer side lengths with either width 1 or height 1 (or both).
There is an n×m grid, and each cell is colored either black or white. A tiling is a way to place bricks onto the grid such that each black cell is covered by exactly one brick, and each white cell is not covered by any brick. In other words, bricks are placed on black cells only, cover all black cells, and no two bricks overlap.
An example tiling of the first test case using 5 bricks. It is possible to do better, using only 4 bricks.
What is the minimum number of bricks required to make a valid tiling?
砖被定义为边长均为整数的矩形,且其宽度为 1 或高度为 1(或两者同时满足)。
给定一个 n×m 的网格,每个格子被染成黑色或白色。一个铺砌(tiling)是指将若干砖块放置在网格上,使得每个黑色格子恰好被一块砖覆盖,而每个白色格子不被任何砖块覆盖。换言之,砖块仅能放置在黑色格子上,必须覆盖所有黑色格子,且任意两块砖块不能重叠。
第一个测试用例的一种使用 5 块砖的铺砌示例。但可以做得更好,仅需 4 块砖即可。
完成一个合法铺砌所需的最少砖块数量是多少?
输入格式
The first line contains two integers n, m (1≤n,m≤200) — the number of rows and columns, respectively.
The next n lines describe the grid. The i-th of these lines contains a string of length m, where the j-th character denotes the color of the cell in row i, column j. A black cell is given by "#", and a white cell is given by ".".
It is guaranteed that there is at least one black cell.
第一行包含两个整数 n、m(1≤n,m≤200),分别表示行数和列数。
接下来的 n 行描述网格。其中第 i 行是一个长度为 m 的字符串,其第 j 个字符表示第 i 行、第 j 列的单元格颜色。黑色单元格用 “#” 表示,白色单元格用 “.” 表示。
保证至少存在一个黑色单元格。
输出格式
Output a single integer, the minimum number of bricks required.
输出一个整数,即所需的最少砖块数量。
输入输出样例
输入#1
3 4 #.## #### ##..
输出#1
4
输入#2
6 6 ###### ##.... ###### ##...# ##...# ######
输出#2
6
输入#3
10 8 ####..## #..#.##. #..#.### ####.#.# ....#### .###.### ###.#..# ######## ###..### .##.###.
输出#3
18
说明/提示
The first test case can be tiled with 4 bricks placed vertically.
The third test case can be tiled with 18 bricks like this:

第一个测试用例可以用 4 块竖直放置的砖块铺满。
第三个测试用例可以用 18 块砖块按如下方式铺满:

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