二分图---------棋盘覆盖

给定一个N行N列的棋盘,已知某些格子禁止放置。
求最多能往棋盘上放多少块的长度为2、宽度为1的骨牌,骨牌的边界与格线重合(骨牌占用两个格子),并且任意两张骨牌都不重叠。
输入格式
第一行包含两个整数N和t,其中t为禁止放置的格子的数量。
接下来t行每行包含两个整数x和y,表示位于第x行第y列的格子禁止放置,行列数从1开始。
输出格式
输出一个整数,表示结果。
数据范围
1≤N≤1001≤N≤100
输出样例:
8 0

输出样例:
32

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 110;
typedef pair<int, int> PII;
#define x first
#define y second
int n, m;
int dx[4] = {-1, 0, 1, 0}, dy[4] = {0, 1, 0, -1};
bool g[N][N], st[N][N];
PII match[N][N];
bool find(int x, int y){
 for (int i = 0; i < 4; i ++){
  int a = x + dx[i], b = y + dy[i];
  if (a && a <= n && b && b <= n && !g[a][b] && !st[a][b]){
   st[a][b] = true;
   PII t = match[a][b];
   if (t.x == -1 || find(t.x ,t.y)){
    match[a][b] = {x, y};
    return true;
   }
  }
 }
  return false;
}
int main(){
 cin >> n >> m;
 while(m --){
  int x, y;
  scanf("%d%d", &x, &y);
  g[x][y] = true;
 }
  memset(match, -1, sizeof match);
  int res = 0;
 for (int i = 1; i <= n; i ++)
     for (int j = 1; j <= n; j ++)
        if ((i + j) % 2 && !g[i][j]){
         memset(st, 0, sizeof st);
         if (find(i, j))   res ++;
     }
      cout << res << endl;
  return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值