hrbust 1231/hdu 3118 Arbiter【二进制枚举】好题

111 篇文章 0 订阅
75 篇文章 0 订阅

Arbiter
Time Limit: 1000 MSMemory Limit: 131072 K
Total Submit: 16(7 users)Total Accepted: 8(6 users)Rating: Special Judge: No
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).

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.

Output
Output one integer on a single line for each case, indicating the minimum number of channels KMXS must prohibit to avoid mental disorder.
Sample Input
1
3 3
0 1
1 2
2 0

Sample Output
1
Source
2009 Asia Wuhan Regional Contest Online
Recommend
zeropointer

题目大意:

给你N个点,M条无向边,让你求,最少去掉几条边,使得图中没有奇环。


思路:


1、首先我们知道,对应一个二分图,如果其中有环,也是偶环,那么我们首先考虑将图变成一个二分图。


2、对应我们观察到点一共也就15个,我们可以Dfs模拟二进制枚举,暴力枚举出集合X,那么其余的点就是集合Y的。对应我们将集合自身中的无向边去掉之后,那么得到的图就一定是一个只可能存在偶环的一个图,我们在枚举的过程中维护这个最少去掉的边的条数即可。


Ac代码:


#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
int map[500][500];
int vis[500];
int n,m,ans;
void Slove()
{
    int cont=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(vis[i]==vis[j])
            {
                cont+=map[i][j];
            }
        }
    }
    ans=min(ans,cont/2);
}
void Dfs(int now)
{
    if(now==n)
    {
        Slove();
        return ;
    }
    vis[now]=1;
    Dfs(now+1);
    vis[now]=0;
    Dfs(now+1);
}
int main()
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
        memset(map,0,sizeof(map));
        scanf("%d%d",&n,&m);
        for(int i=0;i<m;i++)
        {
            int x,y;
            scanf("%d%d",&x,&y);
            map[x][y]++;
            map[y][x]++;
        }
        memset(vis,0,sizeof(vis));
        ans=0x3f3f3f3f;
        Dfs(0);
        printf("%d\n",ans);
    }
}





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值