POJ 3041 Asteroids (minimum point coverage)

Source: Internet
Author: User

Test instructions: In a n*n matrix, there are m points, each elimination of a row or a column of points, the minimum number of operations;

Idea: The x-axis and the y-axis as two different sets, each row or column as a point, each given point as an edge, so that the two-part map is built;

Eliminate all points, the matrix is completely covered, so as to the minimum point coverage problem;

Minimum cover number = maximum number of matches, so the maximum number of matches is required;

#include <cstdio>#include<cstring>#include<algorithm>#include<cmath>using namespacestd;intT,n,m,shu;intmm[505][505];intvis[500010],link[500010];intDfsintx) {    inti,j,k;  for(i=1; i<=n;i++)    {        if(!vis[i]&&Mm[x][i]) {Vis[i]=1; if(link[i]==-1||DFS (Link[i])) {Link[i]=x; return 1; }        }    }    return 0;}intHungary () {inti,j,k; intsum=0; memset (Link,-1,sizeof(link));  for(i=1; i<=n;i++) {memset (Vis,0,sizeof(VIS)); if(Dfs (i)) sum++; }    returnsum;}intMain () {inti,j,k,u,v;  while(SCANF ("%d%d", &n,&m)! =EOF) {memset (mm,0,sizeof(mm));  for(i=0; i<m;i++) {scanf ("%d%d",&u,&v); MM[U][V]=1; } printf ("%d\n", Hungary ()); }    return 0;}

POJ 3041 Asteroids (minimum point coverage)

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.