POJ-3041 asteroids the minimum point coverage of the binary map

Source: Internet
Author: User

The main idea: in an n * n grid, there are m obstacles, and now you have a weapon, this weapon can eliminate any line or a row of obstacles, now requires all obstacles to eliminate, ask at least how many times the use of this weapon

Problem-solving ideas: Think of long time how to solve the problems of row and column ... How to represent two point sets
Finally suddenly thought, since do not know how to deal with the ranks, the ranks are divided into two points, the point on behalf of the relationship between the row and column, so handed a pitch, a.
In fact, this is really, the line between the ranks (points) as long as the use of certain points can be expressed. Those dots are one of the endpoints of all the lines, so the dots can draw all the lines and all the lines can be expressed, indicating that all the obstacles can be expressed. So the problem turns out to be the smallest point coverage problem.

#include <cstdio>#include <vector>#include <cstring>using namespace STD;Const intN =510; vector<int>Row[n];intN, M, Vis[n], link[n];voidInit () { for(inti =1; I <= N; i++) row[i].clear ();intx, y; for(inti =0; I < m; i++) {scanf("%d%d", &x, &y);    Row[x].push_back (y); }memset(Link,0,sizeof(link));}BOOLDfsintu) { for(inti =0; I < row[u].size (); i++) {if(Vis[row[u][i]])Continue; Vis[row[u][i]] =1;if(!link[row[u][i] | | DFS (LINK[ROW[U][I])) {Link[row[u][i]] = u;return true; }    }return false;}voidHungary () {intAns =0; for(inti =1; I <= N; i++) {memset(Vis,0,sizeof(VIS));if(Dfs (i)) ans++; }printf("%d\n", ans);}intMain () { while(scanf("%d%d", &n, &m)! = EOF) {init ();    Hungary (); }return 0;}

POJ-3041 asteroids the minimum point coverage of the binary map

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.