Test Instructions: Each ' * ' needs a 1*2 of things to cover, ask at least how many 1*2 to cover these ' * 'Analysis: Just ask for the maximum number of completely covered, and then add the points that cannot be completely covered. The code of the G-question has been changed just a bit. ********************************************************************* #include <stdio.h >
#include <string.h>
#include <queue>
usingnamespaceStd
ConstintMAXN =1005;///number of points after processing
ConstintMAXM = -;///Original Size
ConstintOO = 1e9+7;
CharG[MAXM][MAXM];intN, M;///Save Original
intINDEX[MAXM][MAXM];///give me the number.
structedge{intV, Next;} e[maxn*4];
intHEAD[MAXN], CNT;///the processed side
intMX[MAXN], MY[MAXN];///record the point to which it matches
intUSED[MAXN], DX[MAXN], DY[MAXN];///dx,dy The depth after Dfs is recorded
intdepth, NX;///The depth of the search, and the number of points
voidInIt ()
{///Initialize
NX = CNT =0;
memset (Head,-1,sizeof(Head));
memset (Mx,false,sizeof(Mx));
memset (My,false,sizeof(My));
}
voidAddedge (intUintV
{///Adding edges
E[CNT].V = v;
E[cnt].next = Head[u];
Head[u] = cnt++;
}
BOOLBFS ()
{///wide search to find out the level, and determine whether there is an augmented path exists
queue<int> Q;
depth = oo;
memset (DX,false,sizeof(DX));
memset (DY,false,sizeof(DY));
for(intI=1; i<=nx; i++)
{
if(Mx[i] = =false)
{
Dx[i] =true;
Q.push (i);
}
}
while(Q.size ())
{
intU = Q.front (); Q.pop ();
if(Dx[u] > depth) Break;///have found that the upper layer exists augmented road
for(intJ=head[u]; j!=-1; J=e[j].next)
{
intv = e[j].v;
if(Dy[v] = =false)
{
DY[V] = Dx[u] +1;
if(My[v] = =false)
depth = Dy[v];
Else
{
dx[My[v]] = Dy[v] +1;
Q.push (My[v]);
}
}
}
}
returnDepth! = oo;
}
BOOLDFS (intI
{
for(intJ=head[i]; j!=-1; J=e[j].next)
{
intv = e[j].v;
if(Used[v] = =false&& Dx[i] = = dy[v]-1)
{
USED[V] =true;///start forgetting to set a visit at fault once
if(My[v] && dy[v] = = depth)
Continue;
if( ! MY[V] | | DFS (My[v]))
{
MY[V] = i;
Mx[i] = v;
returntrue;
}
}
}
returnfalse;
}
intKarp ()
{
intAns =0;
while(BFS () = =true)
{
memset (Used,false,sizeof(used));
for(intI=1; i<=nx; i++)
{
if( ! Mx[i] && DFS (i))
ans++;
}
}
///because the point is on both sides, so it repeats once and the result should go out 2
returnAns/2;
}
intMain ()
{
intI, J, T;
scanf"%d", &t);
while(t--)
{
scanf"%d%d", &m, &n);
intsum =0;///record number of ' * '
InIt ();
for(i=0; i<m; i++)
{
scanf"%s", G[i]);
for(j=0; j<n; J + +)
{
if(G[i][j] = ='*')
{///Purchase Relationship Diagram
INDEX[I][J] = ++nx;///give me the number.
sum++;
if(J! =0&& g[i][j-1] =='*')
{///matches to the left.
Addedge (Index[i][j], index[i][j-1]);
Addedge (index[i][j-1], index[i][j]);
}
if(I! =0&& g[i-1][J] = ='*')
{///with the above can match
Addedge (Index[i][j], index[i-1][J]);
Addedge (index[i-1][J], index[i][j]);;
}
}
}
}
intans = Karp ();
printf"%d\n", Sum-ans);
}
return0;
}
H-antenna placement-hdu 3020 (binary image matching)