Topic links
The main topic: 01 Matrix, you can put the horse in 0 position, in order to do not attack the premise of the maximum number of
Puzzle: Can attack the position of the two-way edge, two-point graph maximum Matching
My Harvest: Loved ~ ~ ~
#include <bits/stdc++.h> using namespace std;
const int n=205;
const int m=n*n;
int n,cnt;
int t,head[m];
int vis[m],lik[m],id[n][n];
Char S[n][n];
int dd[8][2]={-1,-2,-1,2,-2,-1,-2,1,1,2,1,-2,2,1,2,-1}; struct Edge{int To,nex;}
E[10000005];
void Add (int u,int v) {e[t].to=v,e[t].nex=head[u],head[u]=t++;}
int hungry (int x,int Tim) {for (int i=head[x];i!=-1;i=e[i].nex) {int v=e[i].to;
if (Vis[v]==tim) continue;
Vis[v]=tim; if (!lik[v]| |
Hungry (Lik[v],tim)) return lik[v]=x;
} return false;
} void Build () {for (int. i=1;i<=n;i++) {for (int j=1;j<=n;j++) {if (s[i][j]== ' 0 ') {
id[i][j]=++cnt;
for (int k=0;k<8;k++) {int x=i+dd[k][0],y=j+dd[k][1]; if (x<1| | x>n| | y<1| | y>n| |
s[x][y]== ' 1 ') continue;
Add (Id[i][j],id[x][y]), add (Id[x][y],id[i][j]); }
}
}
}
}
void work () {int ans=0;
for (int i=1;i<=cnt;i++) ans+= (bool) hungry (i,i);
cout<<cnt-ans/2<<endl;
} void Init () {scanf ("%d", &n); Memset (Head,-1,sizeof (head));
for (int i=1;i<=n;i++) scanf ("%s", s[i]+1);
Build ();
} int main () {init ();
Work ();
return 0; }