HDU 1281 board game (Hungary (max match + enumeration ))

Source: Internet
Author: User
Http://acm.hdu.edu.cn/showproblem.php? PID = 1281 Problem description James and gardon are playing a game: For an N * m board, put as many "cars" as possible in chess boxes ", 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 3 4 1 1 3 2 2 2 3 3 3 4 1 3 2 1 3 3 2

 

Sample outputboard 1 have 0 important blks for 2 chessmen. Board 2 have 3 important blks for 3 chessmen.

How can we understand that this question is the biggest matching question? The following uses the first group of data as an example:

3 3 4

1 2

1 3

2 1

2 2

For a link (1, 2) and (1, 3), you can select only one link because the two of them are in the same X coordinate.

Understand why it is the largest match!

This layer is easy to understand. You can directly apply the template.

Code :
 1 # Include <iostream> 2   Using   Namespace  STD; 3   Int Map [ 110 ] [ 110 ], CX [ 110 ], Mark [ 110 ], CY [ 110  ], M, N;  4   Int PATH ( Int  V)  5   {  6       Int I;  7       For (I = 1 ; I <= m; I ++ )  8           If (Map [v] [I] &! Mark [I])  9   {  10 Mark [I] = 1  ;  11               If (! CY [I] |PATH (CY [I])  12   {  13 CX [v] = I;  14 CY [I] = V;  15                   Return   1  ;  16   }  17   }  18      Return   0  ;  19   }  20   Int  Maxmatch ()  21   {  22 Memset (CX, 0 , Sizeof  (CX ));  23 Memset (CY, 0 ,Sizeof  (CY ));  24       Int I, sum = 0  ;  25       For (I = 1 ; I <= N; I ++ )  26           If (! CX [I])  27   {  28 Memset (mark,0 , Sizeof  (Mark ));  29 Sum + = PATH (I );  30   }  31       Return  SUM;  32   }  33   Int  Main ()  34   { 35       Int T, A, B, K = 1  ;  36       While (~ Scanf ( "  % D  " , & N, & M ,& T ))  37   {  38 Memset (map, 0 , Sizeof  (MAP )); 39           While (T -- )  40   {  41 Scanf ( "  % D  " , & ,& B );  42 Map [a] [B] = 1  ;  43   }  44          Int Ans = Maxmatch ();  45           Int I, j, Count = 0  ;  46           For (I = 1 ; I <= N; I ++ )  47               For (J = 1 ; J <= m; j ++ )  48                   If (Map [I] [J])  49   {  50 Map [I] [J] = 0  ;  51                       If (ANS! = Maxmatch ())  52 Count ++ ;  53 Map [I] [J] = 1  ;  54  }  55 Printf ( "  Board % d have % d important blanks for % d chessmen. \ n  " , K ++ , Count, ANS );  56   }  57       58       Return   0  ;  59 }

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.