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"