Arbiter HDU - 3118

原题链接
考察:状压dp
  虽然在二分图题单里...但我感觉是考察的状压dp..
思路:
  \(n<=15\),枚举二进制,0是一个集合,1是一个集合.二分图存在当且仅当图内两点集合不存在边.我们求最小的边集合即可.

Code

#include <iostream>
#include <cstring>
using namespace std;
const int N = 20;
int n,m,g[N][N];
int get(int st,int x)
{
	int res = 0;
	for(int i=0;i<n;i++)//n*n*2^n
	  if((st>>i&1)==x)
	    for(int j=i;j<n;j++)
	      if((st>>j&1)==x)
	        res+=g[i][j];
	return res;
}
int main()
{
	int T;
	scanf("%d",&T);
	while(T--)
	{
		scanf("%d%d",&n,&m);
		memset(g,0,sizeof g);
		while(m--)
		{
			int a,b;
			scanf("%d%d",&a,&b);
			g[a][b]++,g[b][a]++;
		}
		int res = 0x3f3f3f3f;
		for(int i=0;i<1<<n;i++)
		{
			int t = get(i,0)+get(i,1);
			res = min(t,res);
		}
		printf("%d\n",res);
	}
	return 0;
}
posted @ 2021-07-15 10:43  acmloser  阅读(18)  评论(0编辑  收藏  举报