POJ 1274 The Perfect Stall

题目链接:POJ 1274 The Perfect Stall

题目大意:
POJ 1274 The Perfect Stall

题解:
二分图匹配模板。

#include <cstring>
#include <iostream>
using namespace std;
#define io_speed_up ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)

int n, m, link[210], ans;
bool vis[210], g[210][210];

bool hungry(int now) {
    for (int i = 1; i <= n; i++) {
        if (!vis[i] && g[now][i]) {
            vis[i] = true;
            if (!link[i] || hungry(link[i])) {
                link[i] = now;
                return true;
            }
        }
    }
    return false;
}

int main() {
    io_speed_up;
    while (cin >> n >> m) {
        memset(g, 0, sizeof(g));
        memset(link, 0, sizeof(link));
        for (int i = 1, s, x; i <= n; ++i) {
            cin >> s;
            while (s--) {
                cin >> x;
                g[i][x] = true;
            }
        }
        ans = 0;
        for (int i = 1; i <= n; ++i) {
            memset(vis, 0, sizeof(vis));
            ans += hungry(i);
        }
        cout << ans << endl;
    }
    return 0;
}
上一篇:ios之UI中自定义cell


下一篇:git push代码时弹框提示验证,跳转浏览器输入密码后不能点击验证按钮