poj3041-Asteroids , 二分图的最小顶点覆盖数 = 最大匹配数

2015-07-24 05:33:38 · 作者: · 浏览: 7

点击打开链接

二分图的最小顶点覆盖数 = 二分图的最大匹配数


题意: 在N*N的网络中有K颗小行星。小行星i的位置是(Ri, Ci)。现在有一个强力的武器能够用一发光束将一整行或一整列的小行星消灭。想要利用这个武器消灭所有的小行星最少需要几发光束?

分析: 以小行星的左右坐标建立二分图,就可以看出是求二分图的最小顶点覆盖数。


#include 
  
   
#include 
   
     #include 
    
      #include 
     
       using namespace std; const int maxn = 500 + 5; //单侧顶点的最大数目 struct BPM{ int n, m; //左右顶点个数 vector
      
        G[maxn]; //邻接表 int left[maxn];//left[i]为右边第i个点的匹配点编号,-1表示不存在 bool T[maxn];//T[i]为右边第i个点是否已标记 int right[maxn]; //求最小覆盖用 bool S[maxn]; //求最小覆盖用 void init(int n, int m){ this->n = n; this->m = m; for(int i=0; i
       
        & X, vector
        
         & Y){ int ans = solve(); memset(S, 0, sizeof S ); for(int u =0; u