Learning network flow in ing ... As a beginner practice is essential ~ ~ ~ Composition method because the book is very detailed, so simply say
The beam as the vertex of the graph, the asteroid as the edge of the connection vertex, the map, because the minimum vertex coverage is equal to the maximum matching of two graphs , so the maximum matching of the binary graph can be obtained.
Adjacency Matrix, Dfs seek augmented path, Hungarian algorithm
Adjacency Matrix: Complexity O (n^3)
If using adjacency table: Complexity O (n*m)
#include <cstdio> #include <cstring> #include <cmath> #include <iostream> #include < algorithm> #include <set> #include <map> #include <stack> #include <vector> #include < queue> #include <string> #include <sstream> #define EPS 1e-9#define all (x) X.begin (), X.end () #define INS (x ) Inserter (X,x.begin ()) #define for (I,J,K) for (int i=j;i<=k;i++) using namespace Std;typedef long Long ll;int i,j,k,n,m , X,y,t,ans,big,cas,match[505],g[505][505],r,c;bool flag,vis[505];bool Hungary (int u)//start looking for augmented path {for (int i=1;i<=) from U n;i++) {if (G[u][i]&&!vis[i])//g array storage adjacency matrix, Match[i] represents the node of the current node I match {vis[i]=1; if (match[i]==0| | Hungary (Match[i])) return match[i]=u; }} return 0;} int main () {scanf ("%d%d", &n,&k); for (i=1;i<=k;i++) {scanf ("%d%d", &r,&c); G[r][c]=1; } ans=0; /* Hungarian algorithm process-find the augmented path */for (i=1;i<=n;i++) {memset (Vis,0,sizeof (VIS)); If (Hungary (i)) ans++; }/* Search for End */printf ("%d\n", ans); return 0;}
"Network Flow" POJ 3041 asteroids binary map maximum match-"Challenge Program Design Competition" Example