http://acm.hdu.edu.cn/showproblem.php?pid=5727

题意:n个珠子,每个珠子有阴阳两种属性,且阴的一定和阳的紧邻,排成一个环;m行,每行两个数,表示阳性x珠子和y阴性珠子相邻则功能减弱,问功能减弱珠子最少有几个

思路:二分匹配

全排列阴性珠子,因为是环,O((n-1)!);枚举每个阳性珠子,插入i位置,前提是i前后两个阴性珠子都不与阳性珠子有排斥作用;

最后问题变转化成,阳性珠子和位置的最大匹配问题

 // #pragma comment(linker, "/STACK:102c000000,102c000000")
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
// #include <conio.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define lson l,mid,rt<<1
#define rson mid+1,r,rt<<1|1
const int N = ;
const int M = 1e6+;
const int MOD = 1e9+;
#define LL long long
#define LB long double
#define mi() (l+r)>>1
double const pi = acos(-);
const double eps = 1e-;
void fre() {
freopen("in.txt","r",stdin);
}
// inline int r() {
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
// }
int mp[][];
int a[];
int n,m;
int ans;
bool vis[];
int b[];
vector<int>s[];
bool dfs(int x){
if(vis[x]) return false;
vis[x]=;
for(int i=;i<(int)s[x].size();i++){
int v=s[x][i];
if(b[v]==-||dfs(b[v])){
b[v]=x;
return true;
}
}
return false;
} void hungarian(){
clc(b,-);
int tem=;
for(int i=;i<=n;i++){
clc(vis,);
if(dfs(i))
tem++;
}
if(tem>ans) ans=tem;
}
void work(){
for(int i=;i<n;i++){
a[i]=i+;
}
do{
for(int i=;i<=;i++) s[i].clear();
for(int i=;i<n;i++){
int k1=a[i],k2=a[(i-+n)%n];
for(int j=;j<=n;j++){
if(!mp[k1][j]&&!mp[k2][j]) s[j].push_back(i);
}
}
hungarian();
}while(next_permutation(a+,a+n)&&ans!=n);
}
int main(){
// fre();
while(~scanf("%d%d",&n,&m)){
clc(mp,);
ans=;
for(int i=;i<m;i++){
int x,y;
scanf("%d%d",&x,&y);
mp[y][x]=;
}
work();
printf("%d\n",n-ans);
}
return ;
}

HDU5727 Necklace的更多相关文章

  1. HDU5727 Necklace(二分图匹配)

    Problem Description SJX has 2*N magic gems. N of them have Yin energy inside while others have Yang ...

  2. HDU5727 Necklace(枚举 + 二分图最大匹配)

    题目大概说有n个yang珠子n个yin珠子,要交替串成一个环形项链,有些yang珠子和某个yin珠子相邻这个yang珠子会不高兴,问最少有几个yang珠子不高兴. 自然会想到直接用状压DP去解,转移很 ...

  3. [HDU5727]Necklace(二分图最大匹配,枚举)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5727 题意:有N个阴珠子和N个阳珠子,特定序号的阴阳珠子放在一起会让阳珠子暗淡.现在问排放成一个环,如 ...

  4. HDU5730 Shell Necklace(DP + CDQ分治 + FFT)

    题目 Source http://acm.hdu.edu.cn/showproblem.php?pid=5730 Description Perhaps the sea‘s definition of ...

  5. 2016 Multi-University Training Contest 1 H.Shell Necklace

    Shell Necklace Time Limit: 16000/8000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  6. hdu 5727 Necklace dfs+二分图匹配

    Necklace/center> 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5727 Description SJX has 2*N mag ...

  7. HDU 3874 Necklace (树状数组 | 线段树 的离线处理)

    Necklace Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  8. USACO section1.1 Broken Necklace

    /* ID: vincent63 LANG: C TASK: beads */ #include <stdio.h> #include<stdlib.h> #include&l ...

  9. [BZOJ1789][BZOJ1830][Ahoi2008]Necklace Y型项链

    [BZOJ1789][BZOJ1830][Ahoi2008]Necklace Y型项链 试题描述 欢乐岛上众多新奇的游乐项目让小可可他们玩的非常开心.现在他们正在玩比赛串项链的游戏,谁串的最快就能得到 ...

随机推荐

  1. C++:类型转换

    5.3 类型转换 5.3.1 系统预定义类型间的转换 1. 隐式转换: 例如: int x=5,y;             y=3.5+x; //系统会自动先将int型的5转换为double型的5. ...

  2. windows本地无法启动sqlserver服务

    解决方法:进入服务列表后,选择sqlserver服务,右键然后选择属性,然后在登陆选项卡中,选择本地系统帐户,这样就可以启动sqlserver服务了

  3. 单交换机VLAN虚拟局域网划分

    1.下载Cisco模拟器 Packet Tracer 是由Cisco公司发布的一个辅助学习工具,为学习CCNA课程的网络初学者去设计.配置.排除网络故障提供了网络模拟环境.学生可在软件的图形用户界面上 ...

  4. 初学者的checklist:对于QTP,你应该知道的9个基本概念

    学习QTP或者其他相关任何工具的方法都是首先把基本的概念过一遍.正所谓砍柴不怕磨刀功,一旦你对这些概念熟悉了,你就可以学习该工具的高级部分了.写这篇文章的目标是列出初学QTP的人应该掌握的所有基本概念 ...

  5. hdu 4911 Inversion (分治 归并排序 求逆序数)

    题目链接 题意:给n个数,求交换k次相邻的数之后的最小的逆序数对. 用分治的方法,以前在poj上做过这种题,昨天比赛的时候忘了.... 下面的归并排序还是以前的模板. #include <ios ...

  6. Catalog与Schema

    按照SQL标准的解释,在SQL环境下Catalog和Schema都属于抽象概念,可以把它们理解为一个容器或者数据库对象命名空间中的一个层次,主要用来解决命名冲突问题.从概念上说,一个数据库系统包含多个 ...

  7. bzoj4048 3928

    羞耻,分组赛上考的,竟然没想出来, 对坐标离散化后区间dp即可,竟然还双倍经验 ; ..,..] of longint; v:..] of longint; a,b,h:..] of longint; ...

  8. php linux部署相关

    http://www.itbulu.com/wdcp-php55.html http://www.wdlinux.cn/wdcp/install.html http://www.yiichina.co ...

  9. Java [Leetcode 70]Climbing Stairs

    题目描述: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either ...

  10. DirectDraw 直接显示RGB图象的最简单实现

      来自:   #include "DDraw.h" class CDDraw { public: void CleanUp(); void DrawDIB(BITMAPINFOH ...