标签:
4 3 2 2 1 3 3
YES
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <algorithm> 5 using namespace std; 6 const int maxn = 33*33; 7 bool mp[maxn][maxn],used[maxn],cant[50][50]; 8 int Link[maxn],n,m,k; 9 bool match(int u){ 10 for(int i = 0; i < maxn; ++i){ 11 if(!mp[u][i] || used[i]) continue; 12 used[i] = true; 13 if(Link[i] == -1 || match(Link[i])){ 14 Link[i] = u; 15 return true; 16 } 17 } 18 return false; 19 } 20 int main(){ 21 int x,y; 22 while(~scanf("%d%d%d",&n,&m,&k)){ 23 memset(cant,false,sizeof cant); 24 for(int i = 0; i < k; ++i){ 25 scanf("%d%d",&y,&x); 26 cant[x-1][y-1] = true; 27 } 28 memset(mp,false,sizeof mp); 29 for(int i = 0; i < n; ++i){ 30 for(int j = 0; j < m; ++j){ 31 if(((i+j)&1) && !cant[i][j]){ 32 if(i > 0 && !cant[i-1][j]) mp[i*m + j][(i-1)*m + j] = true; 33 if(j > 0 && !cant[i][j-1]) mp[i*m + j][i*m + j - 1] = true; 34 if(i + 1 < n && !cant[i+1][j]) mp[i*m + j][(i+1)*m + j] = true; 35 if(j + 1 < m && !cant[i][j+1]) mp[i*m + j][i*m + j + 1] = true; 36 } 37 } 38 } 39 int ret = 0; 40 memset(Link,-1,sizeof Link); 41 for(int i = 0; i <= m*n; ++i){ 42 memset(used,false,sizeof used); 43 if(match(i)) ++ret; 44 } 45 printf("%s\n",n*m - k == 2*ret?"YES":"NO"); 46 } 47 return 0; 48 }
标签:
原文地址:http://www.cnblogs.com/crackpotisback/p/4854144.html