HDU 1281 board game "dichotomy match"

Source: Internet
Author: User

Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=1281

Test instructions: Chinese topic, not described.

Solution: The row X of the chessboard as the point of the left side of the two graphs, the column y as the right point of the second graph, then the position can be placed as an edge of the car, and the maximum matching of the binary map X is not the same, Y is not the same, so each match is not the same row, so the largest match is the And to determine how many points are must be put, as long as the maximum match, each time to remove a match, and then to calculate whether the result is the same as the original maximum number of matches, if the same is not necessary, if not the same is necessary.

Code:

#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace STD;structnode{intXintY;} it[10010];intp[510][510];intN, M, K;intA, B;intbook[510];intmatch[510];BOOLDfsintu) { for(inti =1; I <= m; i++) {if(Book[i] = =0&& P[u][i] = =1) {Book[i] =1;if(Match[i] = =0|| DFS (Match[i])) {Match[i] = u;return true; }        }    }return false;}intMain () {intCA =1; while(scanf("%d%d%d", &n, &m, &k)! = EOF) {memset(P,0,sizeof(p));memset(Match,0,sizeof(match)); for(inti =0; I < K; i++) {scanf("%d%d", &a, &b);            it[i].x = A;            It[i].y = b; P[A][B] =1; }intAns =0; for(inti =1; I <= N; i++) {memset(Book,0,sizeof(book));if(Dfs (i)) ans++; }intTMP =0; for(intj =0; J < K; J + +) {P[it[j].x][it[j].y] =0;intANS1 =0;memset(Match,0,sizeof(match)); for(inti =1; I <= N; i++) {memset(Book,0,sizeof(book));if(Dfs (i)) ans1++; }if(ans1! = ans) tmp++; P[IT[J].X][IT[J].Y] =1; }printf("Board%d has%d important blanks for%d chessmen.\n", Ca++,tmp,ans); }return 0;}

HDU 1281 board game "dichotomy 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.