zoukankan      html  css  js  c++  java
  • poj1274

    匈牙利算法

    View Code
    #include <iostream>
    #include
    <cstdio>
    #include
    <cstdlib>
    #include
    <cstring>
    using namespace std;

    #define MAXN 205

    int uN, vN;
    bool g[MAXN][MAXN];
    int xM[MAXN], yM[MAXN];
    bool chk[MAXN];

    bool SearchPath(int u)
    {
    int v;
    for ( v= 0; v < vN; v++)
    if (g[u][v] && !chk[v])
    {
    chk[v]
    = true;
    if (yM[v] == -1 || SearchPath(yM[v]))
    {
    yM[v]
    = u;
    xM[u]
    = v;
    return true;
    }
    }
    return false;
    }

    int MaxMatch()
    {
    int u, ret = 0;
    memset(xM,
    -1, sizeof(xM));
    memset(yM,
    -1, sizeof(yM));
    for (u = 0; u < uN; u++)
    if (xM[u] == -1)
    {
    memset(chk,
    false, sizeof(chk));
    if (SearchPath(u))
    ret
    ++;
    }
    return ret;
    }

    void input()
    {
    memset(g,
    0, sizeof(g));
    for (int i = 0; i < uN; i++)
    {
    int a;
    scanf(
    "%d", &a);
    for (int j = 0; j < a; j++)
    {
    int b;
    scanf(
    "%d", &b);
    b
    --;
    g[i][b]
    = true;
    }
    }
    }

    int main()
    {
    //freopen("t.txt", "r", stdin);
    while (scanf("%d%d", &uN, &vN) != EOF)
    {
    input();
    printf(
    "%d\n", MaxMatch());
    }
    return 0;
    }
  • 相关阅读:
    歌德巴赫猜想
    Dice Possibility
    ACboy needs your help(简单DP)
    Bag of mice(概率DP)
    合唱队形(LIS)
    地震预测(模拟链表)
    关于KMP算法的感想
    Card Collector
    LOOPS
    Aeroplane chess(简单概率dp)
  • 原文地址:https://www.cnblogs.com/rainydays/p/2155956.html
Copyright © 2011-2022 走看看