# poj 2446 Chessboard

### 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”.

4 3 2
2 1
3 3

YES

### Hint

A possible solution for the sample input.

### Code

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#define N 35
using namespace std;
struct ss
{
int next,to;
};
ss Edge[N*N*2];
int n,m,k,tot;
bool used[N*N];
bool map[N][N];
bool ll[N*N];
int f[N*N];

void clear()
{
tot=0;
memset(map,false,sizeof(map));
memset(ll,0,sizeof(ll));
}

{
Edge[tot].to=y;
}

bool dfs(int u)
{
{
int to=Edge[i].to;
if(!used[to])
{
used[to]=true;
if(f[to]==-1||dfs(f[to]))
{
f[to]=u;
return true;
}
}
}
return false;
}

int hungary()
{
int cnt=0;
memset(f,-1,sizeof(f));
for(int i=1;i<=n*m;i++)
{
if(ll[i])continue;
memset(used,0,sizeof(used));
if(dfs(i))cnt++;
}
return cnt;
}

int main()
{
while(scanf("%d%d%d",&n,&m,&k)!=EOF)
{
clear();
for(int i=1;i<=k;i++)
{
int x,y;
scanf("%d%d",&y,&x);
map[x][y]=true;
}
int pp=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
ll[++pp]=map[i][j];
if(map[i][j])continue;
if(i-1>0&&!map[i-1][j])
{
int x=(i-2)*m+j;
}
if(j-1>0&&!map[i][j-1])
{
int x=(i-1)*m+j-1;
}
}
}
if(hungary()*2==n*m-k)puts("YES");
else puts("NO");
}
return 0;
}


• 本文已收录于以下专栏：

## POJ-2446 Chessboard

• niushuai666
• 2011年12月01日 15:56
• 2977

## POJ - 2446 Chessboard 二分图 最大匹配(输入坑)

• L123012013048
• 2015年06月10日 00:52
• 634

## poj_2446 Chessboard匈牙利算法

• yeruby
• 2014年09月26日 10:36
• 641

## 二分图之poj2446

• y990041769
• 2014年07月16日 11:28
• 2442

## poj 2446(二分匹配) Chessboard

• u010087314
• 2013年05月17日 18:02
• 333

## POJ 2446 Chessboard（匈牙利算法）

Chessboard Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 19211   Ac...
• Shili_Xu
• 2017年09月08日 15:34
• 95

## POJ 2446 Chessboard 二分图

ChessboardTime Limit: 2000MS Memory Limit: 65536K Total Submissions: 19313 Accepted: 60...
• ywq12138
• 2017年10月15日 20:06
• 103

## POJ 2446 Chessboard(匈牙利算法)

• qq_33901573
• 2017年01月06日 10:31
• 58

## POJ 2446 Chessboard（二分图匹配）

• u011643500
• 2014年04月09日 10:51
• 386

## POJ 2446 Chessboard （匈牙利算法）

• z286830682
• 2013年09月18日 20:10
• 635

举报原因： 您举报文章：poj 2446 Chessboard 色情 政治 抄袭 广告 招聘 骂人 其他 (最多只允许输入30个字)