HDU-2063-过山车

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

参考博文:https://blog.csdn.net/qq_41727666/article/details/83825871

                  https://blog.csdn.net/lw277232240/article/details/72615522/#commentBox

#include 

int match[500][500];
int visit[500];
int parter[500];
int M, N;

bool find (int x)
{
    for(int i = 0; i < N; i++)
    {
        if(visit[i] == 0 && match[x][i] == 1)
        {
            visit[i] = 1;
            if(parter[i] == -1 || find(parter[i]))
            {
                parter[i] = x;
                return true;
            }
        }
    }
    return false;
}

int main ()
{
    int K, boy, girl, ans;
    while(scanf("%d", &K) != EOF && K != 0)
    {
        ans = 0;
        scanf("%d%d", &M, &N);
        for(int i = 0; i < N; i++)
        {
            visit[i] = 0;
            parter[i] = -1;
        }
        for(int i = 0; i < M; i++)
        {
            for(int j = 0; j < N; j++)
            {
                match[i][j] = 0;
            }
        }
        while(K--)
        {
            scanf("%d%d", &girl, &boy);
            match[girl-1][boy-1] = 1;
        }
        for(int i = 0; i < M; i++)
        {
            for(int j = 0; j < N; j++)
            {
                visit[j] = 0;
            }
            if(find(i))
                ans++;
        }
        printf("%d\n", ans);
    }
    return 0;
}

 

你可能感兴趣的:(HDUOJ)