Each time you choose to clear an asteroid on one row or column. Choose at least a few times.
The rows and columns are abstracted into points, the I behavior node i+n, the J column is the node J, each planet is an edge, connected to the row.
The problem is then transformed into a minimum point overlay. The minimum point of a binary graph overrides = = maximum match.
#include <cstdio> #include <cstring>const int n=505<<1;int n,vis[n],link[n],g[n][n];int find (int u) { for (int i=1; i<=n*2; i++) if (G[u][i]&&!vis[i]) {vis[i]=1;if (!link[i]| | Find (Link[i])) {Link[i]=u;return 1;}} return 0;} int solve () {memset (link,0,sizeof link), int ans=0;for (int i=1;i<=n;i++) {memset (vis,0,sizeof Vis), if (Find (i)) ans++ ;} return ans;} int main () {int m,u,v;scanf ("%d%d", &n,&m), memset (g,0,sizeof g), while (m--) {scanf ("%d%d", &u,&v); g[u+ N][v]=g[v][u+n]=1;} printf ("%d\n", Solve ());}
"POJ 3041" asteroids (minimum point coverage)