2016 Multi-University Training Contest 1 Necklace 环排+二分匹配
链接:http://acm.hdu.edu.cn/showproblem.php?pid=5727
题意:由2*N颗宝石构成的环(阴阳宝石均为N颗且标号均从1~N) 之后给定M组 a,b;表示阳宝石a若和阴宝石b相邻会使得阳宝石变暗,问所构成的环中阳宝石变暗的最少数量?
其中(1<=N<=9, 1<= M <= N*N)
思路:确定一个阴宝石(我代码中让1不动),其余的环排。
将空隙变成一个点,先将所夹空隙的两点与阳宝石每点建图之后跑匈牙利即可,这跑出来的是最大匹配数(即最多不变暗的阳宝石数);
稍加剪枝还是容易过的;8! = 40320
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include<bits/stdc++.h>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define MS0(a) memset(a,0,sizeof(a))
#define MS1(a) memset(a,-1,sizeof(a))
#define MSi(a) memset(a,0x3f,sizeof(a))
#define inf 0x3f3f3f3f
#define A first
#define B second
#define MK make_pair
#define esp 1e-8
#define zero(x) (((x)>0?(x):-(x))<eps)
#define bitnum(a) __builtin_popcount(a)
#define clear0 (0xFFFFFFFE)
#define mod 1000000007
typedef pair<int,int> PII;
typedef long long ll;
typedef unsigned long long ull;
template<typename T>
void read1(T &m)
{
T x = ,f = ;char ch = getchar();
while(ch <'' || ch >''){ if(ch == '-') f = -;ch=getchar(); }
while(ch >= '' && ch <= ''){ x = x* + ch - '';ch = getchar(); }
m = x*f;
}
template<typename T>
void read2(T &a,T &b){read1(a);read1(b);}
template<typename T>
void read3(T &a,T &b,T &c){read1(a);read1(b);read1(c);}
template<typename T>
void out(T a)
{
if(a>) out(a/);
putchar(a%+'');
}
inline ll gcd(ll a,ll b){ return b == ? a: gcd(b,a%b); }
template<class T1, class T2> inline void gmin(T1& a,T2 b) { if(a > b) a = b; }
template<class T1, class T2> inline void gmax(T1& a,T2 b) { if(a < b) a = b; }
int S[][], f[], n;
int vis[], girl[], line[][];
int dfs(int p)
{
rep1(i,,n){
if(line[p][i] && !vis[i]){
vis[i] = ;
if(!girl[i] || dfs(girl[i])){
girl[i] = p;
return ;
}
}
}
return ;
} void init()
{
MS0(girl);MS0(line);
rep1(i,,n) rep1(j,,n) if(!S[i][f[j]] && !S[i][f[j+]]) line[i][j] = ;
} int solve()
{
init(); //建边
int ans = ;
rep1(i,,n){
MS0(vis);
if(dfs(i)) ans++;
}
return n-ans;
}
int main()
{
//freopen("data.txt","r",stdin);
//freopen("out.txt","w",stdout);
int m, a, b;
while(scanf("%d%d",&n, &m) == ){
MS0(S);
rep1(i,,m){
read2(a,b);
S[a][b] = ;
}
rep1(i,,n) f[i] = i; f[n+] = ;
int ans = inf;
do{
gmin(ans, solve());
}while(next_permutation(f+,f+n+) && ans);
printf("%d\n",ans);
}
return ;
}
2016 Multi-University Training Contest 1 Necklace 环排+二分匹配的更多相关文章
- 2016 Al-Baath University Training Camp Contest-1 I. March Rain —— 二分
题目链接:http://codeforces.com/problemset/gymProblem/101028/I I. March Rain time limit per test 2 second ...
- HDU 5727 Necklace 环排+二分图匹配
这是从山东大学巨巨那里学来的做法 枚举下黑色球的排列总数是8!,然后八个白球可选的位置与左右两个黑球存不存在关系建图就行 这是原话,具体一点,每次生成环排,只有互不影响的才连边 最后:注重一点,n个数 ...
- 2016 Al-Baath University Training Camp Contest-1
2016 Al-Baath University Training Camp Contest-1 A题:http://codeforces.com/gym/101028/problem/A 题意:比赛 ...
- 2016 Al-Baath University Training Camp Contest-1 E
Description ACM-SCPC-2017 is approaching every university is trying to do its best in order to be th ...
- 2016 Al-Baath University Training Camp Contest-1 A
Description Tourist likes competitive programming and he has his own Codeforces account. He particip ...
- 2016 Multi-University Training Contest 1 GCD【RMQ+二分】
因为那时候没怎么补所以就分到了未搞分组里!!!然后因为标题如此之屌吧= =点击量很高,然后写的是无思路,23333,估计看题人真的是觉得博主就是个撒缺.废话不多说了,补题... update////2 ...
- 2016 Al-Baath University Training Camp Contest-1 J
Description X is fighting beasts in the forest, in order to have a better chance to survive he's gon ...
- 2016 Al-Baath University Training Camp Contest-1 I
Description It is raining again! Youssef really forgot that there is a chance of rain in March, so h ...
- 2016 Al-Baath University Training Camp Contest-1 H
Description You've possibly heard about 'The Endless River'. However, if not, we are introducing it ...
随机推荐
- argparse - 命令行选项与参数解析(转)
argparse - 命令行选项与参数解析(译)Mar 30, 2013 原文:argparse – Command line option and argument parsing 译者:young ...
- DataTables warning (table id = 'myTable'): Requested unknown parameter '0' from the data source for row 0
第一种方式:不用在js里设置列Html: <table id="myTable"> <thead> <tr> <th>Title-1 ...
- javaEE的十三个技术规范
java 是一种非常棒的语言,健壮,跨平台运行,屏蔽了具体的平台环境的要求,也就是说只要支持java 虚拟机,就可以运行java程序. 下面,我们一起学习一下J2EE的十三种技术规范. 一.JDBC: ...
- Call to undefined function imagettftext()解决方法
由 老高 发表于 2014-10-03 在 代码人生 分类 老高在一个新环境中装DEDECMS的时候发现后台验证码无法显示.直接搜索一下这个错误,有人说session错误,有的说权限错误等等,这不胡 ...
- display:none与visible:hidden区别
if(list.style.display=='none'){ list.style.display='block'; }else{ ...
- jQuery选择器解释和说明
jQuery选择器的意义在于快速的找出特定的DOM元素,然后添加相应的行为. 基本选择器 //选择 id为 one 的元素 $('#btn1').click(function(){ $('#one') ...
- Spring(3.2.3) - Beans(1): Spring 容器
BeanFactory & ApplicationContext org.springframework.beans.factory.BeanFactory 是最基本的 Spring 容器接口 ...
- jQuery之锚点带动画跳转特效
背景图片为金木研,这是我最爱的一张图. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" &quo ...
- 【SQLServer】将Job运行结果发送电子邮件通知用户
SQLServer2005/2008数据库邮件功能: 1. 启用数据库邮件功能:打开SQL Server 2005 外围应用配置器,选择“功能的外围应用配置器”,选择“数据库邮件”,勾选“启用数据库邮 ...
- Win7显示隐藏文件,隐藏文件夹怎么显示?如何查看?
隐藏文件技术是木马病毒传播最惯用的手法之一,它们利用大部分网友对基础操作的不熟悉特点,逃过用户的发现和检查,显示隐藏文件的标准设置方法大家都会使用,一旦隐藏问题与病毒木马结合起来,比如典型的autor ...