Hdoj 1281 board game

Source: Internet
Author: User


Split-point Bipartite Graph Matching

Board games Time Limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 2146 accepted submission (s): 1250


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.

Authorgardon
Source hangdian ACM training team training competition (VI)


# Include <iostream> # include <cstdio> # include <cstring> # include <algorithm> using namespace STD; int MP [220] [220], n, m, K; int LF [220], RT [220]; int linker [220]; bool used [220]; bool DFS (int u) {for (INT I = 1; I <= m; I ++) {If (MP [u] [I]) if (used [I] = false) {used [I] = true; if (linker [I] =-1 | DFS (linker [I]) {linker [I] = u; return true ;}} return false ;} int Hungary () {int ret = 0; memset (linker,-1, sizeof (linker); fo R (INT I = 1; I <= N; I ++) {memset (used, false, sizeof (used); If (DFS (I )) RET ++;} return ret;} int main () {int CAS = 1; while (scanf ("% d", & N, & M, & K )! = EOF) {memset (MP, false, sizeof (MP); For (INT I = 0; I <K; I ++) {scanf ("% d", LF + I, RT + I); MP [LF [I] [RT [I] = true ;} int Bz = Hungary (); int ans = 0; For (INT I = 0; I <K; I ++) {MP [LF [I] [RT [I] = false; int TMP = Hungary (); If (TMP <BZ) ans ++; MP [LF [I] [RT [I] = true;} printf ("board % d have % d important blanks for % d chessmen. \ n ", CAS ++, ANS, Bz);} return 0 ;}



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.