Topic Links:
http://poj.org/problem?id=2446
Main topic:
Give a n*m matrix, where there is a hole in K place. Tell you the location of the K-pits, and now you need to cover them with a 1*2 rectangular plate.
A matrix that cannot cover a place with a pit. Q: Can I overwrite all but the pits, and if so, output "YES",
Otherwise output "NO".
Ideas:
Considering that the size of the rectangular plate is 1*2, then the adjacent position (i,j) and (x, y) must be (i+j) is odd, (x+y) is an even number.
(I+J) is an even number, and (X+J) is an odd number. In this way, all the points on the graph can be divided into points with an odd number of horizontal coordinates and
A point in which the horizontal ordinate is added to an even number. Then create a bipartite graph with odd points on one side and an even point on the other. If you can use the moment
Plate overlay (i.e. no pits), add edges to the two-part chart. Then figure out the maximum number of two points to match ans, which is the maximum coverage
Rectangle board. Since the specification of each rectangular plate is 1*2, it is to be judged whether it is possible to cover all the places except the pits, just
to be sentenced break ans*2 + K is equal to M*n.
AC Code:
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring>using namespace std;const int MAXN = 33;const int maxm = 1100;bool map[maxm][maxm],mask[maxm];int nx,ny;int cx[maxm],cy[maxm];int G[MAXN][ Maxn];int Findpath (int u) {for (int i = 1; I <= NY; ++i) {if (Map[u][i] &&!) Mask[i]) {mask[i] = 1; if (cy[i] = =-1 | | Findpath (Cy[i])) {Cy[i] = u; Cy[u] = i; return 1; }}} return 0;} int Maxmatch () {for (int i = 1; I <= NX; ++i) cx[i] = 1; for (int i = 1; I <= NY; ++i) cy[i] = 1; int res = 0; for (int i = 1; I <= NX; ++i) {if (cx[i] = = 1) {for (int j = 1; j <= NY; ++j) MASK[J] = 0; Res + = Findpath (i); }} return res;} int main () {int n,m,k,u,v; while (~SCANF ("%d%d%d", &n,&m,&k)) {memset (Map,0,sizeoF (MAP)); memset (g,0,sizeof (G)); for (int i = 1; I <= K; ++i) {scanf ("%d%d", &u,&v); G[U][V] =-1; } int num1,num2; NUM1 = Num2 = 1; for (int i = 1, i <= N; ++i) {for (int j = 1; j <= M; ++j) {if (g[i][j] = = 0) {if ((i+j) &1) g[i][j] = num1++; else g[i][j] = num2++; }}} for (int i = 1; I <= N; ++i) {for (int j = 1; j <= M; ++j) {if (g[i][j]! =-1 && (I+J) &1) {if (G[i-1][j] >= 1) MAP[G[I-1][J]][G[I][J]] = 1; if (G[i+1][j] >= 1) map[g[i+1][j]][g[i][j]] = 1; if (G[i][j-1] >= 1) map[g[i][j-1]][g[i][j]] = 1; if (g[i][j+1] >= 1) map[g[i][j+1]][g[i][j]] = 1; }}} NX = Num1; NY = Num2; int ans = maxmatch (); if (ans*2 + K = = m*n) printf ("yes\n"); else printf ("no\n"); } return 0;}
POJ2446 chessboard "binary graph Max Match"