zoukankan      html  css  js  c++  java
  • hdu 2063 匈牙利算法

    http://acm.hdu.edu.cn/showproblem.php?pid=2063

    男女配对最大数

    匈牙利算法模板

    #include <cstdio>
    #include <cstdlib>
    #include <cmath>
    #include <cstring>
    #include <string>
    #include <queue>
    #include <map>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    #define RD(x) scanf("%d",&x)
    #define RD2(x,y) scanf("%d%d",&x,&y)
    #define RD3(x,y,z) scanf("%d%d%d",&x,&y,&z)
    #define clr0(x) memset(x,0,sizeof(x))
    #define eps 1e-9
    const double pi = acos(-1.0);
    typedef long long LL;
    const int modo = 1e9 + 7;
    const int maxn = 1005;
    int mp[maxn][maxn],link[maxn];
    bool used[maxn];
    bool find(int x,int n)
    {
        for(int i = 0;i <= n;++i){
            if(mp[x][i] && !used[i]){
                used[i] = 1;
                if(!link[i] || find(link[i],n)){
                    link[i] = x;
                    return true;
                }
            }
        }
        return false;
    }
    int main() {
        int k,m,n,x,y;
        while(RD3(k,m,n) == 3){
            clr0(mp);
            while(k--){
                RD2(x,y);
                mp[x][y] = 1;
            }
            clr0(used),clr0(link);
            int ans = 0;
            for(int i = 1;i <= m;++i){
                clr0(used);
                if(find(i,n))
                    ans++;
            }
            printf("%d
    ",ans);
        }
    
        return 0;
    }
    


  • 相关阅读:
    装饰器的应用
    绑定路由关系
    基本使用
    numpy多项式拟合
    pandas空值处理与插值
    索引
    事务
    子查询
    视图
    自关联
  • 原文地址:https://www.cnblogs.com/zibaohun/p/4046787.html
Copyright © 2011-2022 走看看