Board games
Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2492 accepted submission (s): 1452
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 input3 3 41 21 32 12 23 3 41 21 32 13 2
Sample outputboard 1 have 0 important blks for 2 chessmen. Board 2 have 3 important blks for 3 chessmen.
Authorgardon
Source hangdian ACM training team training competition (VI)
Detailed recommend code: minimum coverage point = maximum matching code:
1/* problem: 1281 (board game) Judge Status: Accepted 2 runid: 11517709 language: C ++ Author: huifeidmeng 3 code render status: rendered by hdoj C ++ code render version 0.01 beta */4 5 # include <cstdio> 6 # include <cstring> 7 # include <cstdlib> 8 using namespace STD; 9 const int maxn = 105; 10 static int cont = 1; 11 bool mat [maxn] [maxn], vis [maxn]; 12 INT chess [maxn]; 13 int N, m, K; 14 int match (int x) {15 (INT I = 1; I <= m; I ++) {16 if (MAT [x] [I] &! Vis [I]) {17 vis [I] = 1; 18 if (! Chess [I] | match (chess [I]) {19 chess [I] = x; 20 return 1; 21} 22} 23} 24 return 0; 25} 26 int A [maxn * maxn], B [maxn * maxn]; 27 int main () {28 // freopen ("test. in "," r ", stdin); 29 While (scanf (" % d ", & N, & M, & K )! = EOF) {30 memset (MAT, 0, sizeof (MAT); 31 memset (chess, 0, sizeof (ChEss); 32 for (INT I = 0; I <K; I ++) {33 scanf ("% d", & A [I], & B [I]); 34 mat [A [I] [B [I] = 1; 35} 36 int ans = 0; 37 for (INT I = 1; I <= N; I ++) {38 memset (VIS, 0, sizeof (VIS); 39 ans + = match (I); 40} 41 int res = 0; // number of important points: 42 // judge whether a point is important or not. Remove this point and check whether there is any impact on this match. 43 for (INT I = 0; I <K; I ++) {44 memset (chess, 0, sizeof (ChEss); 45 mat [A [I] [B [I] = 0; // remove the vertex and match 46 int val = 0 again; 47 for (Int J = 1; j <= N; j ++) {48 memset (VIS, 0, sizeof (VIS); 49 Val + = match (j); 50} 51 if (ANS> Val) RES ++; // The description has an effect... is an important point 52 mat [A [I] [B [I] = 1; // restore the removed vertex 53} 54 printf ("board % d have % d important blks for % d chessmen. \ n ", cont ++, res, ANS); 55} 56 return 0; 57}