ArticleDirectory
- Problem description
- Input
- Output
- Sample Input
- Sample output
- Author
- Source
Time Limit: 2000/1000 ms (Java/other) memory limit: 65536/32768 K (Java/other) total submission (s): 5 accepted submission (s): 4 Font: Times New Roman | Verdana | Georgia Font Size: Bytes → Problem description James and gardon are playing a game: For an N * m board, place as many "cars" as possible in the grid as possible in chess ", this makes it easy for them not to attack each other, But gardon restricts that only some grids can be placed. xiaoxi easily solves this problem (see) note that the locations where vehicles cannot be placed do not affect the mutual attack of vehicles.
So gardon wants to solve a more difficult problem. While there are as many "cars" as possible, some grids in the board can be avoided. That is to say, if you do not place a car on these grids, you can also ensure that as many "cars" as possible are put down. However, if some grids are left empty, they cannot be placed as many "cars" as possible. Such grids are called important points. Gardon wants John to figure out how many important points are there. Can you solve this problem?
The input contains multiple groups of data,
The first line contains three numbers: n, m, and K (1 <n, m <= 100 1 <k <= N * m), indicating the height and width of the Board, and the number of grids that can be placed with "cars. The next K lines describe the information of all grids: each row contains two numbers x and y, indicating the position of the grid in the checker. Output:
Board t have C important blanks for L chessmen. sample input
3 3 41 21 32 12 23 3 41 21 32 13 2
Sample output
Board 1 have 0 important blanks for 2 chessmen. Board 2 have 3 important blks for 3 chessmen.
Authorgardonsource hangdian ACM training team training competition (VI) Code :
# Include < Stdio. h >
# Include < Iostream >
Using Namespace STD;
# Define Maxn 105
Int G [maxn] [maxn];
Int UN, vn;
Int Linker [maxn];
Bool Used [maxn];
Bool DFS ( Int U)
{
Int V;
For (V = 1 ; V <= Vn; V ++ )
If (G [u] [v] &&! Used [v])
{
Used [v] = True ;
If (Linker [v] =- 1 | DFS (linker [v])
{
Linker [v] = U;
Return True ;
}
}
Return False ;
}
Int Hungary ()
{
Int Res = 0 , U;
Memset (linker, - 1 , Sizeof (Linker ));
For (U = 1 ; U <= UN; u ++ )
{
Memset (used, 0 , Sizeof (Used ));
If (DFS (u) res ++ ;
}
Return Res;
}
Int Main ()
{
Int K, X, Y;
Int I, J;
Int Ans;
Int Icase = 0 ;
While (Scanf ( " % D " , & UN, & Vn, & K) ! = EOF)
{
Icase ++ ;
Memset (G, 0 , Sizeof (G ));
While (K -- )
{
Scanf ( " % D " , & X, & Y );
G [x] [Y] = 1 ;
}
Ans = Hungary ();
Int CNT = 0 ;
For (I = 1 ; I <= UN; I ++ )
For (J = 1 ; J <= Vn; j ++ )
{
If (G [I] [J] = 1 )
{
G [I] [J] = 0 ;
If (ANS > Hungary () CNT ++ ;
G [I] [J] = 1 ;
}
}
Printf ( " Board % d have % d important blanks for % d chessmen. \ n " , Icase, CNT, ANS );
}
Return 0 ;
}