Title Description Description
There is a NXM unit in the grid, some of which are ponds and other squares are land. If you want to overwrite the matrix area of the 1x2 (covering process does not allow any part overlap), the land area can be covered up to a maximum.
Enter a description input Description
The first line of the input file is two integers n,M (1<=n,m<=100), the second behaves as an integer K (k<=50), The next K-line, two integers per line, X, Y represents the row and column position of the K-reservoirs. (1<=X<=N,1<=y<=M).
outputs description output Description
The maximum area block (1x2 area) covered by the output.
sample input to sample
4 4
6
1 1
1 4
2 2
4 1
4 2
4 4
Sample output Sample outputs
4
A matrix in this topic covers 2 land, so we can divide the land into two groups by number of land, adjacent to the two land has a side link, you can do a binary map of the maximum matching search, attention needs to exclude the pond.
Present Code
1#include <cstdio>2#include <cstring>3 BOOLwat[101][101],map[101][101],use[101][101];4 intn,m,k,ans,px,py;5 int from[101][101][2],t[5]={0,1,-1,0,0},tt[5]={0,0,0,1,-1};6 BOOLFindintXinty)7 {8 for(intI=1; i<=4; i++)//search around for viable augmented paths9 {TenPx=x+t[i];p y=y+Tt[i]; One if(px<=0|| px>n| | py<=0|| py>m| | Wat[px][py])Continue; A if(!wat[px][py] &&!use[px][py]&&!map[px][py])//Exclude reservoirs - { -use[px][py]=true; the if((! from[PX] [PY] [0])|| (Find ( from[PX] [PY] [0], from[PX] [PY] [1]))) - { - from[PX] [PY] [0]=x; - from[PX] [PY] [1]=y; + return true; - } + } A } at return false; - } - intMain () - { -scanf"%d%d%d",&n,&m,&k); - intx, y; in for(intI=1; i<=k;i++) - { toscanf"%d%d",&x,&y); +wat[x][y]=true; - } the for(intI=1; i<=n;i++) * for(intj=1; j<=m;j++) $ if((i%2&& J%2) || (i%2==0&& j%2==0)) map[i][j]=1;//Select the Red 1Panax Notoginseng for(intI=1; i<=n;i++) - { the for(intj=1; j<=m;j++) + { A if(!wat[i][j]&&Map[i][j]) the { +memset (use,0,sizeof(use)); - if(Find (I,J)) ans++; $ } $ } - } -printf"%d", ans); the return 0; -}
Codevs1022---Hungarian algorithm