匈牙利算法模板

#include
#include
#include
#include
#include
using namespace std;    
const int N = 510;
bool line[N][N],used[N];
int link[N];
int n, m, nn, mm;
bool find(int x)
{
    for (int i = 1; i <= 53; i++)
    {
        if (line[x][i] == true && used[i] == false)
        {
            used[i] = true;
            if (link[i] == -1 || find(link[i]))
            {
                link[i] = x;
                return true;
            }
        }
    }
    return false;
}
int answer()
{
    int num = 0;
    for (int i = 1; i <= 53; i++)
    {
        memset(used, 0, sizeof(used));
        if (find(i))
        {
            num++;
        }
    }
    return num;
}

 

你可能感兴趣的:(匈牙利算法模板)