微信小程序换肤功能实现方法详细步骤与探讨
671
2022-08-27
poj 2446 Chessboard(经典二分匹配)
题目:class="data-table" data-id="t7a7e9d1-TANLPiFA" data-transient-attributes="class" data-width="1162px" style="width: 100%; outline: none; border-collapse: collapse;">
Time Limit: 2000MS
Memory Limit: 65536K
Total Submissions: 15250
Accepted: 4751
Description
Alice and Bob often play games on chessboard. One day, Alice draws a board with size M * N. She wants Bob to use a lot of cards with size 1 * 2 to cover the board. However, she thinks it too easy to bob, so she makes some holes on the board (as shown in the figure below).
We call a grid, which doesn’t contain a hole, a normal grid. Bob has to follow the rules below:
1. Any normal grid should be covered with exactly one card.
2. One card should cover exactly 2 normal adjacent grids.
Some examples are given in the figures below:
A VALID solution.
An invalid solution, because the hole of red color is covered with a card.
An invalid solution, because there exists a grid, which is not covered.
Your task is to help Bob to decide whether or not the chessboard can be covered according to the rules above.
Input
There are 3 integers in the first line: m, n, k (0 < m, n <= 32, 0 <= K < m * n), the number of rows, column and holes. In the next k lines, there is a pair of integers (x, y) in each line, which represents a hole in the y-th row, the x-th column.
Output
If the board can be covered, output "YES". Otherwise, output "NO".
Sample Input
4 3 22 1 3 3
Sample Output
YES
Hint
A possible solution for the sample input.
分析:一眼能看出这是二分匹配吗?所以我觉得这很经典(当然我也是听了别人的思路才懂的)。一张卡片是1*2的规模,所以一个格子就有上下左右四种可能的相邻的格子与他组合成卡片(没有hole),这就是匹配的雏形,于是用邻接表把所有格子的各种匹配情况都表示出来,最后用匈牙利最大匹配求出结果再与总的格子数,holes数做关系比较就能得到最终的判断。
#include
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~