zoukankan      html  css  js  c++  java
  • HDU-2119-Matrix(最大匹配)

    链接:https://vjudge.net/problem/HDU-2119#author=Smilencer

    题意:

    众所周知,tyz是一个写bug小能手,以至于如果没有队友的帮助,就ac不了程序。 
    今天可怜的XJL又被抓来出数据debug了,你要帮助他以最少的样例消灭所有程序的bug 
    数据以矩阵的形式表示出来,整个矩阵中只包含0,1两个数。其中1代表一个bug。 
    已知每出一个样例可以消灭一行或者一列的bug,即把一行或一列所有的1变成0。 
    你的任务是求出最少需要找多少个样例才能使得整个程序没有bug,即矩阵中的1全部被清除 

    思路:

    x,y建立二分图。

    代码:

    #include <iostream>
    #include <memory.h>
    #include <string>
    #include <istream>
    #include <sstream>
    #include <vector>
    #include <stack>
    #include <algorithm>
    #include <map>
    #include <queue>
    #include <math.h>
    #include <cstdio>
    #include <set>
    #include <iterator>
    #include <cstring>
    using namespace std;
    
    typedef long long LL;
    const int MAXN = 5e3+10;
    int Next[4][2] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
    
    vector<int> G[MAXN];
    int Map[110][110];
    int Link[MAXN], Vis[MAXN];
    int n, m, k;
    
    bool Dfs(int x)
    {
        for (int node = 1;node <= m;node++)
        {
            if (Map[x][node] && Vis[node] == 0)
            {
                Vis[node] = 1;
                if (Link[node] == -1 || Dfs(Link[node]))
                {
                    Link[node] = x;
                    return true;
                }
            }
        }
        return false;
    }
    
    int Solve()
    {
        memset(Link, -1, sizeof(Link));
        int cnt = 0;
        for (int i = 1;i <= n;i++)
        {
            memset(Vis, 0, sizeof(Vis));
            if (Dfs(i))
                cnt++;
        }
        return cnt;
    }
    
    int main()
    {
        while (~scanf("%d", &n) && n)
        {
            scanf("%d", &m);
            for (int i = 1;i <= n;i++)
                for (int j = 1;j <= m;j++)
                    scanf("%d", &Map[i][j]);
            int cnt = Solve();
            printf("%d
    ", cnt);
        }
    
        return 0;
    }
    

      

  • 相关阅读:
    Java 学习使用常见的开源连接池
    Java 数据库操作
    Java 集合的简单理解
    windows中在vs code终端使用bash
    敏捷开发、DevOps相关书籍——书单
    使用Dockerfile来构建镜像
    Redis集群搭建
    使用redis限制ip访问次数
    NFS服务器搭建
    ssh 中 远程文件传输
  • 原文地址:https://www.cnblogs.com/YDDDD/p/10872326.html
Copyright © 2011-2022 走看看