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