Title Link: http://poj.org/problem?id=3041
In a n*n map, there are m and obstacles, you can eliminate a row or a row of obstacles each time, ask you to eliminate at least a few times to remove all obstacles.
Using a binary graph to connect rows (left) and columns (to the right) with obstructions, such as (2,3), there is an obstacle, then the left 2 and 3 sides on the right. The number of edges is the number of obstacles, the number of points is the number of times, so the problem becomes a little point covering all the edges, that is, the minimum point coverage problem. In a binary graph, the minimum point overwrite = maximum number of matches.
1 //minimum point overwrite = maximum match2#include <iostream>3#include <cstdio>4#include <cstring>5#include <vector>6 using namespacestd;7 Const intN =505;8 structEdge {9 intnext, to;Ten}edge[n*N]; One intHead[n], CNT, match[n]; A BOOLVis[n]; - - voidinit () { thememset (Match,-1,sizeof(Match)); -Memset (Head,-1,sizeof(head)); -memset (Vis,false,sizeof(Vis)); -CNT =0; + } - +InlinevoidAddintU,intv) { AEdge[cnt].next =Head[u]; atEdge[cnt].to =v; -Head[u] = cnt++; - } - - BOOLDfsintu) { - for(inti = Head[u]; ~i; i =Edge[i].next) { in intv =edge[i].to; - if(!Vis[v]) { toVIS[V] =true; + if(Match[v] = =-1||DFS (Match[v])) { -MATCH[V] =u; the return true; * } $ }Panax Notoginseng } - return false; the } + A intHungry (intN) { the intres =0; + for(inti =1; I <= N; ++i) { -memset (Vis,false,sizeof(Vis)); $ if(Dfs (i)) $res++; - } - returnRes; the } - Wuyi intMain () the { - intN, M, U, v; Wu while(~SCANF ("%d%d", &n, &m)) { - init (); About for(inti =0; I < m; ++i) { $scanf"%d%d", &u, &v); - Add (U, v); - } -printf"%d\n", Hungry (n)); A } + return 0; the}
POJ 3041 Asteroids (minimum point coverage of the binary chart)