Test instructions: Classic binary graph matching problem. A n*n matrix is given, which has a k obstacle. A single star cannon can be clear of a row or a row of obstacles. The minimum number of cannons.
Practice: You can consider the maximum point coverage. The left vertex of the map is a row and the right vertex is a column. If there is an obstacle, connect the edge. At this point the maximum point coverage is the minimum number of cannon, which is the maximum matching of the binary graph. You can use the Hungarian algorithm.
1 /*--------------------------------------------------------------------------------------*/2 //Helica ' s header3 //Second Edition4 //2015.11.75 //6#include <algorithm>7#include <iostream>8#include <cstring>9#include <ctype.h>Ten#include <cstdlib> One#include <cstdio> A#include <vector> -#include <string> -#include <queue> the#include <stack> -#include <cmath> -#include <Set> -#include <map> + - //Debug function for a n*m array + #defineDebug_map (n,m,g) printf ("\ n"); for (int i=0;i< (N); i++) A{ for(intj=0;j< (M); J + +){ atprintf"%d", G[i][j]);} printf"\ n");} - //Debug function for int,float,double,etc. - #defineDebug_var (X) cout<< #X "=" <<X<<endl; - /*--------------------------------------------------------------------------------------*/ - using namespacestd; - in Const intMAXN = -+Ten; - intun,vn; to intg[2*maxn][2*MAXN],LINKER[MAXN]; + BOOLUSED[MAXN]; - the BOOLDfsintu) * { $ for(intv=1; v<=vn;v++)Panax Notoginseng { - if(g[u][v]&&!)Used[v]) the { +USED[V] =true; A if(Linker[v] = =-1||DFS (Linker[v])) the { +LINKER[V] =u; - return true; $ } $ } - } - return false; the } - Wuyi intHungary () the { - intres =0; Wumemset (linker,-1,sizeoflinker); - for(intu=1; u<=un;u++) About { $memset (Used,false,sizeof(used)); - if(Dfs (U)) res++; - } - returnRes; A } + the intn,k,m,t; - $ intMain () the { the while(~SCANF ("%d%d",&n,&K)) the { thememset (G,0,sizeofG); -UN = VN =N; in for(intI=0; i<k;i++) the { the intx, y; Aboutscanf"%d%d",&x,&y); theG[x][y] =1; the } theprintf"%d\n", Hungary ()); + } -}
POJ 3041-asteroids-binary Map matching