The labels of the rows and columns make up the x and Y sets, and then if the x, Y coordinates can be placed in the car, a line is connected between the Xs and y points, and no peers and trains do not attack each other, so finding the maximum match is the maximum number of cars that can be placed and then enumerating each point to determine whether it is an important
#include <iostream> #include <stdio.h> #include <string.h>using namespace std; #define N 102int map[n][ N],visit[n],match[n];int n,m,k;struct node{int x, y;} Rc[n*n];bool DFS (int k) {for (int i=1;i<=m;i++) {if (visit[i]| |! Map[k][i]) continue; Visit[i]=1; if (!match[i]| | DFS (Match[i])) {match[i]=k; return true; }} return false;} int Match () {memset (match,0,sizeof (match)); int cnt=0; for (int i=1;i<=n;i++) {memset (visit,0,sizeof (visit)); if (DFS (i)) cnt++; } return CNT;} int main () {int i,t=1; while (scanf ("%d%d%d", &n,&m,&k)!=eof) {memset (map,0,sizeof (map)); for (i=1;i<=k;i++) {scanf ("%d%d", &rc[i].x,&rc[i].y); Map[rc[i].x][rc[i].y]=1; } int Num=0,ans; Ans=match (); for (i=1;i<=k;i++) {map[rc[i].x][rc[i].y]=0; if (Ans>match ()) num++; Map[rc[i].x][rc[i].y]=1;} printf ("Board%d has%d important blanks for%d chessmen.\n", T++,num,ans); } return 0;}
HDU 1281 Board Game