标签:匈牙利 freopen ems .com 矩阵 while zoj geo continue
传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1059
保存匈牙利模板。
#include <cstdio>
#include <cstring>
const int maxn = 205;
const char _outp[2][5] = {"No", "Yes"};
int T, n, left[maxn], ans;
char g[maxn][maxn], cover[maxn];
bool dfs(int i) {
for (int j = 1; j <= n; ++j) {
if (!g[i][j] || cover[j]) {
continue;
}
cover[j] = 1;
if (!left[j] || dfs(left[j])) {
left[j] = i;
return true;
}
}
return false;
}
int main(void) {
//freopen("in.txt", "r", stdin);
scanf("%d", &T);
while (T--) {
scanf("%d", &n);
ans = 0;
memset(left, 0, sizeof left);
for (int i = 1; i <= n; ++i) {
for (int j = 1; j <= n; ++j) {
scanf("%d", (int*)(g[i] + j));
}
}
for (int i = 1; i <= n; ++i) {
memset(cover, 0, sizeof cover);
if (dfs(i)) {
++ans;
}
}
puts(_outp[ans == n]);
}
return 0;
}
_bzoj1059 [ZJOI2007]矩阵游戏【二分图匹配】
标签:匈牙利 freopen ems .com 矩阵 while zoj geo continue
原文地址:http://www.cnblogs.com/ciao-sora/p/6193790.html