【题解】zhx154嬲


所谓只有偶环,是指无奇环,也就是二分图
由于n只有20,直接爆搜。枚举每个点在左或右,然后判断即可。
代码

#include <cmath>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <queue>
using namespace std;
//加强版:HDU3118 状压
//一下为zhx弱版:嬲   暴力 
int G[30][30], n, m, ans = 2000, turn[30], x, y; 
int cut(){
	int res = 0;
	for(int i = 1; i <= n; i++){
		for(int j = i+1; j <= n; j++){
			if(turn[i] == turn[j]){
				res+=G[i][j];
			}
		}
	}
	return res;
}
void dfs(int i){
	if(i == n){
		/*if(ans > cut()){
			
			ans = cut();
		}for(int j = 1; j <= n; j++)	cout << turn[j] <<" ";
			cout << endl;*/
		ans = min(ans, cut());
		turn[i] = 1;
		ans = min(ans, cut());
		/*if(ans > cut()){
			
			ans = cut();
		}for(int j = 1; j <= n; j++)	cout << turn[j] <<" ";
			cout << endl;*/
		return;
	}	
	
	turn[i] = 0;
	dfs(i+1);
	turn[i] = 1;
	dfs(i+1);
}
int main()
{
//	int t;
//	cin >> t;
//	while(t--){
		ans = 2000;
		memset(G, 0, sizeof(G));
		cin >> n >> m;
		for(int i = 1; i <= m; i++){
			cin >> x >> y;
			G[x][y]++;
			G[y][x]++;
		}
		dfs(1);
		cout << ans << endl;
//	}
	 
	return 0;
}

posted @ 2020-04-25 21:38  _Buffett  阅读(155)  评论(0编辑  收藏  举报