Bipartite graph matching problem minimal covering set of points

// some simple ideas bipartite graph
 // Minimum coverage point bipartite graph: assume a selected point equivalent to covering all its sides endpoint
 // Minimum bipartite graph cover set (the set of the set of X and Y selected minimum point may be all of the figures are covered edges)
 // minimal covering set point number == maximum matching of bipartite graph
 @ conclusions.: https://www.cnblogs.com/jianglangcaijin/p/6035945 .html (ORZ)
 // example HDU 2119 (board) 
#include <the iostream> 
#include <cstdio> 
#include <CString>
 the using  namespace STD;
 const  int MAXN = 100 + 15 ;
 BOOL Grape [MAXN] [MAXN]; / / ideas: horizontal and vertical axes to establish a bipartite graph, if Grape [i] [j ] == true, then there is an edge between prove ij, is converted to the smallest coverage point set problem 
int n-, m;
bool vis[maxn];
int match[maxn];
bool Hungary(int u)//寻找增广路
{
    for(int v=1;v<=m;++v)
    {
        if(!vis[v]&&Grape[u][v])
        {
            vis[v] = true;
            if(match[v]==-1||Hungary(match[v]))
            {
                match[v] = u;
                return true;
            }
        }
    }
    return false;
}
int solve()
{
    memset(match,-1,sizeof(match));
    int cnt = 0;
    for(int u=1;u<=n;++u)
    {
        memset(vis,false,sizeof(vis));
        if(Hungary(u))
            ++cnt;
    }
    return cnt;
}
int main()
{
    while(cin>>n&&n)
    {
        cin>>m;
        for(int i=1;i<=n;++i)
            for(int j=1;j<=m;++j)
                cin>>Grape[i][j];
        cout<<solve()<<endl;
    }
}

// identification is completed, I was rubbish

Guess you like

Origin www.cnblogs.com/newstartCY/p/11569489.html