Problem description and Gardon play a game: to a n*m chess board, in the lattice to put as much as possible some chess inside the "car", and so they can not attack each other, which is of course very simple, but Gardon limited only some lattice can be put, Xiaoxi is still easy to solve the problem (see) Note that the location of the car 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 more than one set of data, the first row 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 "car". 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 4 1 2 1 3 2 1 2 2 3 3 4 1 2 1 3 2 1 3 2 Sample Outputboard 1 has 0 important blanks for 2 chessmen. Board 2 has 3 important blanks for 3 chessmen. Authorgardon
#include <iostream>#include<cstring>#include<cstdio>#include<cmath>using namespacestd;BOOLmp[ the][ the];BOOLvisit[ the];intmatch[ the];intn,m;intDfsinti) { for(intj =1; j<=m;j++) { if(visit[j]| |! MP[I][J])Continue; VISIT[J]=1; intQ =Match[j]; MATCH[J]=i; if(q = =0|| DFS (q))return 1; MATCH[J]=Q; } return 0;}intMain () {intK,i,j,z =0; while(cin>>n>>m>>k) {Z++; Memset (MP,0,sizeof(MP)); for(i =0; i<k;i++) { intb; scanf ("%d%d",&a,&b); MP[A][B]=1; } intsum =0; memset (Match,0,sizeof(match)); for(i =1; i<=n;i++) {memset (visit,0,sizeof(visit)); Sum+=DFS (i); } intnum =0; for(i =1; i<=n;i++) { for(j =1; j<=m;j++) { if(!mp[i][j])Continue; MP[I][J]=0; intTsum =0; memset (Match,0,sizeof(match)); for(intt =1; t<=n;t++) {memset (visit,0,sizeof(visit)); Tsum+=DFS (t); } if(tsum!=sum) num++; MP[I][J]=1; }} printf ("Board%d has%d important blanks for%d chessmen.\n", z,num,sum); } return 0;}
hdu1281 board Game