Title Description Description
A rectangle can be divided into m*n small squares, in which some small squares cannot be used. A domino occupies two small squares adjacent to each other. How many dominoes can be placed in the entire area without overlapping, and not occupy any small squares that are marked as unusable.
Enter a description Input Description
The first line has two positive integers m and n separated by a space.
The second line has a positive integer k, which indicates that a total of k small squares are not available. Input data guarantees k<=m*n.
The following k lines each row has two X and Y separated by a space, indicating that the nth square of the X row cannot be used.
Output Description Output Description
The maximum number of dominoes the output can put.
Sample Input Sample Input
3 3
2
1 1
2 2
Sample Output Sample Output
3
data range and tips Data Size & Hint
For 30% of data, m=1;
For 50% of data,m<=2;
For 70% of data,m<=3;
For 100% of data, m<=50,n<=50.
/*the problem of binary graph matching is to select as many relationships as possible from a lump of lattice relationships, so that each square is selected only once. By observing we can find that the horizontal axis plus ordinate is an even number of squares can only match the odd squares, so it becomes a two-point graph matching problem. */#include<cstdio>#include<iostream>#include<cstring>#defineN 51using namespacestd;intg[n][n],n,m,p,head[n*n],cnt;intused[n*n],belong[n*N];structnode{intV,pre;}; Node E[n*n*2];voidAddintXinty) {e[++cnt].v=y; E[cnt].pre=Head[x]; HEAD[X]=CNT;}BOOLFindinti) { for(intj=head[i];j;j=e[j].pre) { if(!USED[E[J].V]) {USED[E[J].V]=1; if(!belong[e[j].v]| |find (BELONG[E[J].V])) {BELONG[E[J].V]=i; return true; } } } return false;}intMain () {Freopen ("jh.in","R", stdin); scanf ("%d%d%d",&n,&m,&p); for(intI=1; i<=p;i++){ intX,Y;SCANF ("%d%d",&x,&y); G[x][y]=1; } for(intI=1; i<=n;i++){ for(intj=1; j<=m;j++){ if((i+j&1)|| G[I][J])Continue; if(!g[i-1][j]&&i-1>=1) Add ((I-1) *m+j, (I-2) *m+j); if(!g[i+1][j]&&i+1<=n) Add ((I-1) *m+j,i*m+j); if(!g[i][j-1]&&j-1>=1) Add ((I-1) *m+j, (I-1) *m+j-1); if(!g[i][j+1]&&j+1<=M) Add ((I-1) *m+j, (I-1) *m+j+1); } } inttot=0; for(intI=1; i<=n;i++){ for(intj=1; j<=m;j++){ if((i+j&1)|| G[I][J])Continue; memset (Used,0,sizeof(used)); if(Find (I-1) (*M+J)) tot++; }} printf ("%d", tot); return 0;}
Domino (Codevs 3052)