其他分享
首页 > 其他分享> > BZOJ 1059. [ZJOI2007]矩阵游戏

BZOJ 1059. [ZJOI2007]矩阵游戏

作者:互联网

 

就是二分图匹配,直接匈牙利即可。

#include <bits/stdc++.h>

const int N = 220;
bool used[N];
int hascow[N], n, link[N][N];

bool find(int x) {
    for (int i = 1; i <= n; i++) {
        if (link[x][i] && !used[i]) {
            used[i] = 1;
            if (!hascow[i] || find(hascow[i])) {
                hascow[i] = x;
                return 1;
            }
        }
    }
    return 0;
}

int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        scanf("%d", &n);
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++)
                scanf("%d", &link[i][j]);
            hascow[i] = 0;
        }
        int ans = 0;
        for (int i = 1; i <= n; i++) {
            memset(used, 0, sizeof(used));
            ans += find(i);
        }
        if (ans == n) puts("Yes");
        else puts("No");
    }
    return 0;
}
View Code

 

标签:include,int,1059,bool,ZJOI2007,hascow,find,BZOJ
来源: https://www.cnblogs.com/Mrzdtz220/p/12233376.html