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. SSL/TLS/WTLS原理

    一 前言 首先要澄清一下名字的混淆:1 SSL(Secure Socket Layer)是netscape公司设计的主要用于web的安全传输协议.这种协议在WEB上获得了广泛的应用.2 IETF(ww ...

  2. python 下划线的使用(转载:安生犹梦 新浪博客)

    Python 用下划线作为变量前缀和后缀指定特殊变量. _xxx      不能用'from module import *'导入 __xxx__ 系统定义名字 __xxx    类中的私有变量名 核 ...

  3. Android Studio安装、配置

    Google在2013年I/O大会上发布了Android Studio,AndroidStudio是一个基于IntelliJ IDEA的Android开发工具.这个IDE要比eclipse智能很多,具 ...

  4. POJ2891——Strange Way to Express Integers(模线性方程组)

    Strange Way to Express Integers DescriptionElina is reading a book written by Rujia Liu, which intro ...

  5. Android ActionBar的Overlay模式如何不遮盖顶部内容的问题

    关于actionbar的overlay模式请参考 如何让android的actionbar浮动且透明 一文.这篇文章讲的是如何在这种模式下让actionbar不遮住顶部的内容. 这 一般是这样的场景, ...

  6. Junit使用教程(四)

    一.会用Spring测试套件的好处 在开发基于Spring的应用时,如果你还直接使用Junit进行单元测试,那你就错过了Spring为我们所提供的饕餮大餐了.使用Junit直接进行单元测试有以下四大不 ...

  7. vs2012 arcgis engine 10 丢失arcgis模板

    1.Visual Studio 2012环境下安装ArcGIS Engine 10 Visual Studio 2012环境下安装ArcObject SDK for the Microsoft .Ne ...

  8. nodejs抓网易NBA数据

    var http = require("http");var cheerio = require("cheerio"); var url = "htt ...

  9. android中给TextView或者Button的文字添加阴影效果

    1在代码中添加文字阴影 TextView 有一个方法 /**      * Gives the text a shadow of the specified radius and color, the ...

  10. C#手动回收内存的简单方法

    C#有自动回收内存的机制,但是有时自动回收有一定滞后,需要在变量使用后迅速回收,节约内存,这里介绍一个最简单的方法. 1.先对对象赋值 null; 2.System.GC.Collect(); 代码样 ...