HDU 1281 board game two points match

Source: Internet
Author: User

Board gamesTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 2758 Accepted Submission (s): 1613


Problem description and Gardon play a game: to a n*m chess board, in the lattice to put as much as possible some chess inside the "car", and so they can not attack each other, which is of course very simple, but Gardon limited only some lattice can be put, Xiaoxi is still easy to solve the problem (see) Note that the location of the car does not affect the car's mutual attack.
So now Gardon want to let Xiao-Xi to solve a more difficult problem, in order to ensure as much as possible "car" premise, some of the board can be avoided, that is, not on these squares to put the car, but also to ensure that as much as possible "car" was put down. However, if some lattice does not put the son, there is no guarantee to put as much as possible "car", such a lattice is called to do important points. Gardon want to figure out how many of these important points, can you solve this problem?

Input inputs contain multiple sets of data,
The first line has three numbers N, M, K (1<n,m<=100 1<k<=n*m), indicating the height and width of the board, and the number of squares that can be put "cars". The next K-line describes all the lattice information: two x and y per line, indicating the position of the lattice in the checkerboard.

Output for each set of data entered, as shown in the following format:
Board T has 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 has 0 important blanks for 2 chessmen. Board 2 has 3 important blanks for 3 chessmen.
I started with the output of the topic is very confused ... Read someone else's code to understand. The first number is the T Group test data, the second number is the L important point, the third number refers to the maximum matching value


< Span style= "font-size:18px" The problem can be seen as a two-point match between rows and columns, because each row can have at most one pawn per column. Line I and J are matched on behalf of the Chessboard I row J column this position to place the pawn. So, the point on the board is the side of the dichotomy; the number of "cars" is the maximum number of matches for the two graphs. The key to the problem is to ask for important points. It is assumed that the maximum number of matches is ans and that a certain matching strategy has been obtained.
1: Enumerate all the points that can be placed, remove a point (the dot on the board, that is, the side of the dichotomy), and get a new dichotomy.
If   (the maximum number of new binary graphs = = ans)

Then this point is not important.
else//That is, the new binary graph does not reach the ANS this match number, then this point is must put, otherwise cannot reach ans. --Important side
Then Count +1
2: But this enumeration is inefficient. In fact, deleting edges only takes into account the matching edges that are found (because the number of matches obtained by deleting unmatched edges does not change). In this way, the complexity is reduced by simply removing the ans edge.
Further analysis, after deleting an edge, there is no need to re-delete the new two-dimensional graph of the maximum match, just check the deletion after the matching---> can find a new augmented chain on it. In this way, the complexity of the time is further reduced.
3: Such optimizations are undesirable:
When judging whether there is an augmented path, it is not possible to find the augmented path simply by deleting the vertex of the matching edge.
The correct method is: With the deletion of the new binary graph of all the unmatched vertices to do augmentation, can not find the augmented path, matching can no longer increase

Ideas for reference: http://blog.csdn.net/mishifangxiangdefeng/article/details/7109139


Code:

 #include <stdio.h> #include <string.h> #define SIZE 110bool map[size][size], Vis[size];int pre[size], N, m, k; int col[size*size], row[size*size]; int find (int pos) {for (int i = 1; I <= m; ++i) {if (!vis[i] && map[pos][i]) {vis[i] = true; if (pre[i] = = 1 | | find (pre[i)) {Pre[i ] = pos; return 1;}}} return 0;} int Maxmatch () {memset (pre,-1,sizeof (PRE)), int sum = 0, for (int i = 1; I <= n; ++i) {memset (vis,false,sizeof (Vis)); Su M + = find (i);} return sum;}  int main () {int t = 0, while (~scanf ("%d%d%d", &n,&m,&k)) {memset (map,false,sizeof (map)); for (int i = 0; i < K ; ++i) {scanf ("%d%d", &col[i],&row[i]); Map[col[i]][row[i]] = true;} int ans = Maxmatch (), L = 0, cnt = 0, for (int i = 0; i < K; ++i) {Map[col[i]][row[i]] = false; int cnt = Maxmatch () ; if (Cnt<ans) ++l; Map[col[i]][row[i]] = true;} printf ("Board%d has%d important blanks for%d chessmen.\n", ++t,l,ans);} return 0;} 

with June


HDU 1281 board game two points match

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.