题意:
要在一个矩阵中放1*2的长方形..有些点不能放长方形.问最多可以放多少个....
题解:
这题我第一反应是状态压缩DP..但是看范围.好吧..二分图匹配..但是有个问题..如果直接的点对点的做边..会出现混乱..并且不符合2分图的基本模型(同侧的点无直接的任何关系才行)...所以做二分图..第一件事就是把点分成内部不会直接影响的两堆..本题以(x+y)为奇数或偶数来分成两堆..剩下的就很裸了..
Program:
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<cmath>
#include<stack>
#include<queue>
#define ll long long
#define MAXN 105
using namespace std;
int n,match[MAXN],hash[MAXN][MAXN],w[MAXN*MAXN][2];
bool arc[MAXN][MAXN],used[MAXN],s[MAXN][MAXN];
bool dfs(int x)
{
int i;
for (i=1;i<=n;i++)
if (arc[x][i] && !used[i])
{
used[i]=true;
if (!match[i] || dfs(match[i]))
{
match[i]=x;
return true;
}
}
return false;
}
int getmax()
{
int sum=0;
memset(match,0,sizeof(match));
for (int i=1;i<=n;i++)
{
memset(used,false,sizeof(used));
sum+=dfs(i);
}
return sum;
}
int main()
{
int i,j,x,y,m,num,cases=0;
while (~scanf("%d%d",&n,&m) && n)
{
memset(s,true,sizeof(s));
scanf("%d",&num);
while (num--) { scanf("%d%d",&x,&y),s[x][y]=false; };
num=0;
memset(hash,0,sizeof(hash));
for (x=1;x<=n;x++)
for (y=1;y<=m;y++)
if (s[x][y]) hash[x][y]=++num,w[num][0]=x,w[num][1]=y;
memset(arc,false,sizeof(arc));
for (x=1;x<=n;x++)
for (y=1;y<=m;y++)
if ((x+y)%2 && s[x][y])
{
if (x!=1 && s[x-1][y]) arc[hash[x][y]][hash[x-1][y]]=true;
if (y!=1 && s[x][y-1]) arc[hash[x][y]][hash[x][y-1]]=true;
if (x!=n && s[x+1][y]) arc[hash[x][y]][hash[x+1][y]]=true;
if (y!=m && s[x][y+1]) arc[hash[x][y]][hash[x][y+1]]=true;
}
n=num;
if (cases) printf("\n");
cases++;
printf("%d\n",getmax());
for (i=1;i<=n;i++)
if (match[i])
printf("(%d,%d)--(%d,%d)\n",w[match[i]][0],w[match[i]][1],w[i][0],w[i][1]);
}
return 0;
}