zoukankan      html  css  js  c++  java
  • _bzoj1059 [ZJOI2007]矩阵游戏【二分图匹配】

    传送门: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;
    }
    

      

  • 相关阅读:
    jdk安装
    ubuntu 搜狗输入法成功安装
    matlab load
    matlab save 命令
    数字信号处理的思考
    非最大值抑制nms
    HMM,MEMM,CRF模型
    [bzoj2301][HAOI2011]Problem b
    [洛谷P3935]Calculating
    [bzoj4816][Sdoi2017]数字表格
  • 原文地址:https://www.cnblogs.com/ciao-sora/p/6193790.html
Copyright © 2011-2022 走看看