POJ 3041 asteroids "Hungarian algorithm"

Source: Internet
Author: User

Title Link: http://poj.org/problem?id=3041

Test instructions: There are planets on the n*n matrix that can only be placed in one row or column at a time to eliminate all the planets in the bank or column, and to eliminate the minimum number of bullets consumed by all planets.

Solution: A binary graph that behaves as a vertex set, as another vertex set. The topic turns into the least selected point (x or Y), so that it is adjacent to all the edges from these points, which is actually the minimum point coverage problem.

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;intp[510][510];intNintKintb;intbook[510];intmatch[510];BOOLDfsintu) { for(inti =1; I <= N; 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 () { while(scanf("%d%d", &n,&k)!=eof) {memset(P,0,sizeof(p));memset(Match,0,sizeof(match)); while(k--) {scanf("%d%d", &a,&b); P[A][B] =1; }intAns =0; for(intI=1; i<=n;i++) {memset(Book,0,sizeof(book));if(Dfs (i)) ans++; }printf("%d\n", ans); }return 0;}

POJ 3041 asteroids "Hungarian algorithm"

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.