Poj 1548 Robots minimum path matching solution
// Minimum path overwrite = N-maximum match
# Include
# Include
# Include
# Include
Using namespace std;
Const int maxn = 30*30;
Int line [maxn] [maxn];
Int vis [maxn];
Int match [maxn];
Int N;
Int find (int start)
{
Int I;
For (I = 1; I <= N; I ++)
{
If (line [start] [I] &! Vis [I])
{
Vis [I] = 1;
If (match [I] =-1 | find (match [I])
{
Match [I] = start;
Return 1;
}
}
}
Return 0;
}
Void Match ()
{
Memset (match,-1, sizeof (match ));
Int ans = 0;
For (int I = 1; I <= N; I ++)
{
Memset (vis, 0, sizeof (vis ));
If (find (I ))
Ans ++;
}
Printf ("% d \ n", N-ans );
}
Struct node
{
Int x, y;
} Gar [maxn];
Int main ()
{
Int a, B;
// Freopen ("in.txt", "r", stdin );
While (scanf ("% d", & a, & B) & (! =-1 & B! =-1 ))
{
Memset (line, 0, sizeof (line ));
If (! A &&! B)
{
Printf ("0 \ n ");
Continue;
}
N = 0;
While (a & B)
{
Gar [++ N]. x =;
Gar [N]. y = B;
Scanf ("% d", & a, & B );
}
Memset (line, 0, sizeof (line ));
For (int I = 1; I <= N; I ++)
For (int j = I + 1; j <= N; j ++)
{
If (gar [I]. x <= gar [j]. x & gar [I]. y <= gar [j]. y)
Line [I] [j] = 1;
Else if (gar [I]. x> = gar [j]. x & gar [I]. y> = gar [j]. y)
Line [j] [I] = 1;
}
Match ();
}
Return 0;
}