5 5 10 0 1 1 1 1 2 2 1 3 3 1 4 4 2 1 5 2 2 6 2 3 7 2 4 8 3 3 9 4 3 0
3
虽然是模版重要的是学习建模
/*=============================================================================
#
#      Author: liangshu - cbam 
#
#      QQ : 756029571 
#
#      School : 哈尔滨理工大学 
#
#      Last modified: 2015-08-29 12:00
#
#     Filename: B.cpp
#
#     Description: 
#        The people who are crazy enough to think they can change the world, are the ones who do ! 
=============================================================================*/
#
#include<iostream>
#include<sstream>
#include<algorithm>
#include<cstdio>
#include<string.h>
#include<cctype>
#include<string>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
using namespace std;
const int INF=101; 
int from[INF],tot;
bool use[INF];
    int n, m, k;
vector<int>G[INF];
bool match(int x)
{
     for(int i=0;i<G[x].size();i++)
    {
         if(!use[G[x][i]])
        {
             use[G[x][i]]=1;
            if(from[G[x][i]]==-1||match(from[G[x][i]]))
            {
                 from[G[x][i]]=x;
                return 1;
            }
        }
    }
    return 0;
}
int hungary( )
{
     tot=0;
    memset(from,255,sizeof(from));
    for(int i=1;i<= m;i++)
    {
         memset(use,0,sizeof(use));
        if(match(i))
           {
               ++tot;
           }
    }
    return tot;
}
int main(){
    while(cin>>n, n){
        if(n == 0)break;
        cin>>m>>k;
        for(int i = 0; i < k; i++){
            int a, b, c;
           cin>>a>>b>>c;
           G[b].push_back(c);
        }
        int ans = hungary();
        cout<<ans<<endl;
        for(int i = 0; i < INF; i++){
            G[i].clear();
        }
    }
    return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
杭电 HDU ACM 1150 Machine Schedule(二分匹配)
原文地址:http://blog.csdn.net/lsgqjh/article/details/48086345