zoukankan      html  css  js  c++  java
  • 【题解】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;
    }
    
    
  • 相关阅读:
    c++中vector的用法详解[转]
    C++ String
    va_list用法
    如何高效的分析AWR报告
    Oracle存储过程跟踪错误的方法
    Oracle找出锁,并KILL掉
    OracleAWR报告概念和生成
    Linux系统的内存管理
    AIX系统下配置FTP服务
    通过修改注册表配置IE选项
  • 原文地址:https://www.cnblogs.com/ZhengkunJia/p/12775438.html
Copyright © 2011-2022 走看看