zoukankan      html  css  js  c++  java
  • TCO 2015 1A Hard.Revmatching(Hall定理)

    (Description)

    给定一个(n)个点的二分图,每条边有边权。求一个边权最小的边集,使得删除该边集后不存在完备匹配。
    (nleq20)

    (Solution)

    设点集为(S),与(S)中的点相邻的点的并集为(N(S))
    由Hall定理,若存在点集(S)满足(|S|>|N(S)|),则该图不存在完备匹配。
    因为(n)很小,直接枚举所有子集(S)并贪心删相邻点即可。

    另外topcoder跑得快,直接写(2^n imes n^2)就好了。。

    #include <cstdio>
    #include <string>
    #include <vector>
    #include <cstring>
    #include <algorithm>
    #define pb push_back
    using namespace std;
    
    class Revmatching
    {
    public:
    	int sum[23];
    	int smallest(vector<string> A)
    	{
    		int n=A.size(),ans=2e9;
    		for(int s=1,all=1<<n; s<all; ++s)
    		{
    			memset(sum,0,sizeof sum);
    			for(int i=0; i<n; ++i)
    				if(s>>i&1)
    					for(int j=0; j<n; ++j)
    						sum[j]+=A[i][j]-'0';
    			std::sort(sum,sum+n);
    			int res=0;
    			for(int i=n-__builtin_popcount(s); ~i; --i)
    				res+=sum[i];
    			ans=std::min(ans,res);
    		}
    		return ans;
    	}
    };
    
  • 相关阅读:
    字符编码
    IO流技术
    TreeMap使用和Comparable比较
    Collections工具类
    使用迭代器进行遍历时
    238. 除自身以外数组的乘积
    python 字典按键、值排序
    collections.Counter用法
    442. 数组中重复的数据
    1395. 统计作战单位数
  • 原文地址:https://www.cnblogs.com/SovietPower/p/9772532.html
Copyright © 2011-2022 走看看