Board game problem Description and Gardon play a game: to a n*m chess board, in the lattice to put as much as possible some of the "car" inside the chessboard, and so they can not attack each other, which is of course very simple, But Gardon limited only some of the lattice can be put, Xiaoxi still very easy to solve the problem (see) Attention can not put the car in the place does not affect the car's mutual attack.
So now Gardon want to let Xiao-Xi to solve a more difficult problem, in order to ensure as much as possible "car" premise, some of the board can be avoided, that is, not on these squares to put the car, but also to ensure that as much as possible "car" was put down. However, if some lattice does not put the son, there is no guarantee to put as much as possible "car", such a lattice is called to do important points. Gardon want to figure out how many of these important points, can you solve this problem?
Input inputs contain multiple sets of data,
The first line has three numbers N, M, K (1<n,m<=100 1<k<=n*m), indicating the height and width of the board, and the number of squares that can be put "cars". The next K-line describes all the lattice information: two x and y per line, indicating the position of the lattice in the checkerboard.
Output for each set of data entered, as shown in the following format:
Board T has C important blanks for L chessmen.
Sample INPUT3 3 (3) 2 sample Outputboard 1 has 0 important blanks for 2 chessmen. Board 2 has 3 important blanks for 3 chessmen.
#include <cstdio>#include<cstring>#include<vector>#include<algorithm>#definePB Push_backusing namespacestd;intn,m,k,link[ the],vis[ the],x[10005],y[10005];BOOLg[ the][ the];BOOLDfsintu) { for(intI=1; i<=m;i++) { if(!vis[i]&&G[u][i]) {Vis[i]=1; if(link[i]==-1||DFS (Link[i])) {Link[i]=u; return 1; } } } return 0;}intmatch () {intans=0; memset (Link,-1,sizeof(link)); for(intI=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i)) ans++; } returnans;}intMain () {intKase=0; while(SCANF ("%d%d%d", &n,&m,&k)! =EOF) { intans=0; memset (G,0,sizeof(G)); for(intI=0; i<k;i++) {scanf ("%d%d",&x[i],&Y[i]); G[x[i]][y[i]]=1; } intmres=match (); for(intI=0; i<k;i++) {G[x[i]][y[i]]=0; intres=match (); G[x[i]][y[i]]=1; if(res!=mres) ans++; } printf ("Board%d has%d important blanks for%d chessmen.\n",++kase,ans,mres); } return 0;}
HDU 1281 Board Game