HDU 3188 二分图,二进制枚举

解决星际旅行中因精神错乱导致的问题,通过调整星际通道,确保旅途中人员的精神健康。

Arbiter

Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)
Total Submission(s): 1226    Accepted Submission(s): 602

Problem Description
Arbiter is a kind of starship in the StarCraft science-fiction series. The Arbiter-class starship is a Protoss warship specializing in providing psychic support. Arbiters were crewed exclusively by Judicators; unlike other warships that were manned predominantly by Templar. The Judicator used the Arbiter as a base to provide support using space-time manipulation.
Arbiters could weaken space-time, tearing rifts in the fabric of space-time, creating a vortex linking another location to the Arbiter’s location. This could be used to move personnel over long distances between stars.
In the meantime of widely used Arbiter to transfer, KMXS, the captain of one Arbiter, was warning that some person had got a serious mental disorder after the trip on his Arbiter. By using mice as model animals, he found the sake, it’s because of chirality!
Every person has chirality, either left-handed or right-handed. Actually all the persons must live with the food which has the same chirality. When one person took Arbiter from one star to another one, his chirality will be changed (from left-handed to right-handed or from right-handed to left-handed). If a person took a long trip and finally got back to his own star, however, his chirality might be changed to the opposite state other than his original, which would cause fatal mental disorder, or even death.
KMXS has the channels map among the starts and he need to prohibit minimum number of channels from traveling so that wherever a person starts his traveling from when he gets his original star he’ll be safe. KMXS turns to your help.
 
Input
The first line of input consists of an integer T, indicating the number of test cases.
The first line of each case consists of two integers N and M, indicating the number of stars and the number of channels. Each of the next M lines indicates one channel (u, v) which means there is a bidirectional channel between star u and star v (u is not equal to v).
 
Output
Output one integer on a single line for each case, indicating the minimum number of channels KMXS must prohibit to avoid mental disorder.
Constraints
0 < T <= 10
0 <= N <= 15 0 <= M <= 300
0 <= u, v < N and there may be more than one channel between two stars.
 
Sample Input
1
3 3
0 1
1 2
2 0
 
Sample Output
1
 
题意:删除给出的图中的最少的边,让图无奇数边的环
二分图的定义:至少含有2个点,如果有环,环必须是偶数的边。
题解:把题目给的一个图生成一个二分图需要去掉最小的边数量
 1 #include <iostream>
 2 #include <cstring>
 3 using namespace std;
 4 int mapp[20][20],m,n;
 5 int solve(int k){
 6     int ans=0;
 7     for(int i=0;i<n;i++){
 8         for(int j=i+1;j<n;j++){
 9             if(((k&(1<<i))==0)&&((k&(1<<j))==0)){//删除同一集合的点
10                 ans+=mapp[i][j];
11             }
12             if(((k&(1<<i))!=0)&&((k&(1<<j))!=0)){
13                 ans+=mapp[i][j];
14             }
15         }
16     }
17     return ans;
18 }
19 int main(){
20     cin.sync_with_stdio(false);
21     int T,a,b;
22     cin>>T;
23     while(T--){
24         cin>>n>>m;
25         memset(mapp,0,sizeof(mapp));
26         for(int i=0;i<m;i++){
27             cin>>a>>b;
28             mapp[a][b]++;
29             mapp[b][a]++;
30         }
31         if(n==0||m==0){
32             cout<<0<<endl;
33             continue;
34         }
35         int ans=solve(0);
36         for(int i=1;i<(1<<n);i++){//把n个数分成两部分有2^n种状态,每种状态为k,在该状态和第i位同为0的为一个集合,同为1的为另一集合 
37             ans=min(ans,solve(i));
38         }
39         cout<<ans<<endl;
40     }
41     return 0;
42 }

 

 2016-12-05 16:58:37

转载于:https://www.cnblogs.com/xjh-shin/articles/6134571.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值