[POI2008]POD Subdivision of Kingdom
Description
给出一个具有N个结点的无向图,将其分成两个集合S1,S2. 这两个集合的点的个数一样多,但连接它们的边最少.
Input
第一行给出数字N,M,代表有N个点,M条边. 下面M行,每行两个数字代表此两点间有条边.
Output
输出的点集应包含1,且按升序排列
Sample Input
6 8
1 2
1 6
2 3
2 5
2 6
3 4
4 5
5 6
Sample Output
1 2 6
HINT
N<=26
考虑爆搜,带4个参数 len(搜索长度),x(当前搜索到的点),sta(已选择的点的状态),cnt(两个集合之间的边数),但是这样是会T的。时间主要在更新cnt的时候产生了冗余。所以我们把每个点所连的点记为一个状压状态,然后更新cnt的时候减去连边状态中在集合内的点,把不在集合内的点加进来即可。
/*program from Wolfycz*/
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x7f7f7f7f
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
inline int read(){
int x=0,f=1;char ch=getchar();
for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
for (;ch>='0'&&ch<='9';ch=getchar()) x=(x<<1)+(x<<3)+ch-'0';
return x*f;
}
inline void print(int x){
if (x>=10) print(x/10);
putchar(x%10+'0');
}
const int N=26;
int g[(1<<N/2)+10],d[N+10];
int n,m,S,Min=inf;
int get(int sta){return g[sta&((1<<(n>>1))-1)]+g[sta>>(n>>1)];}//分两半统计答案,节省数组空间
void dfs(int num,int x,int sta,int cnt){
if (num==n>>1){
if (Min>cnt) Min=cnt,S=sta;
return;
}
for (int i=x+1;i<=n;i++) dfs(num+1,i,sta|(1<<(i-1)),cnt-get(sta&d[i])+get(~sta&d[i]));//在集合内和不在集合内
}
int main(){
n=read(),m=read();
for (int i=1;i<=m;i++){
int x=read(),y=read();
d[x]|=1<<(y-1);
d[y]|=1<<(x-1);
}
for (int i=1;i<=1<<(n>>1);i++) g[i]=g[i>>1]+(i&1);//记录每个状态内有多少个点
dfs(1,1,1,get(d[1]));
for (int i=1;i<=n;i++) if (S&(1<<(i-1))) printf("%d ",i);
return 0;
}
[POI2008]POD Subdivision of Kingdom的更多相关文章
- 1130: [POI2008]POD Subdivision of Kingdom
1130: [POI2008]POD Subdivision of Kingdom https://lydsy.com/JudgeOnline/problem.php?id=1130 分析: 有效状态 ...
- bzoj1130:[POI2008]POD Subdivision of Kingdom
传送门 看到数据范围这么小,不由得算了一下暴力复杂度,算出来情况一共只有1e7,不多,再乘上暴力判断的复杂度,好像T了,判断的话位运算可以方便解决 但是我写的优化似乎比较渣,还留了个log,但是还是n ...
- 解题:POI 2008 Subdivision of Kingdom
题面 还可以这么搜......学到了(PoPoQQQ orz) 我们最朴素的做法是枚举所有状态(当然可以剪,剪完最终实际状态量也是$C_{26}^{13}$的),然后每次$O(n)$扫一遍判断,大概会 ...
- bzoj AC倒序
Search GO 说明:输入题号直接进入相应题目,如需搜索含数字的题目,请在关键词前加单引号 Problem ID Title Source AC Submit Y 1000 A+B Problem ...
- [POI2008]POD-Subdivision of Kingdom(搜索+状压)
题意 给定一个n个点的无向图,要求将点集分成大小相等的两个子集,使两个子集之间的边数最少 (n<=26) 题解 一开始想了半天DP发现不会,去看题解全是搜索. 所以发现C(1326)可以过我就写 ...
- pod Spec管理配置
pod Spec 为自己的项目添加pod管理功能.前言: 上一篇文章中提到,因为自己在操作的时候遇到很多坑,所在在此做一个记录,同样也希望可以帮到在这个操作上遇到坑的人. 本文将采用配图和加文字的方式 ...
- iOS pod install update 慢!!!
在终端输入: pod install --verbose --no-repo-update pod update --verbose --no-repo-update
- 使用 pod install 还是 pod update ?
翻译自:https://guides.cocoapods.org/using/pod-install-vs-update.html 介绍: 许多人开始使用CocodPods的时候认为pod insta ...
- CocoaPods pod install
加参数可以提升更新的速度 方法1: pod install --verbose --no-repo-update pod update --verbose --no-repo-update 方法2: ...
随机推荐
- uva558 Wormholes SPFA 求是否存在负环
J - Wormholes Time Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit Stat ...
- 运行计划中cost计算方法
概念: blevel:二元高度=索引高度-1 clustering_factor:集群因子,通过索引扫面得出的要查询table的blocks数量,clustering_factor接近table的bl ...
- http://vdceye.com/ 全新页面上线
vdceye manager home page
- 【Mongodb教程 第十五课 】MongoDB 限制记录
Limit() 方法 要限制 MongoDB 中的记录,需要使用 limit() 方法. limit() 方法接受一个数字型的参数,这是要显示的文档数. 语法: limit() 方法的基本语法如下 & ...
- 【转】实现LoadRunner多个场景的顺序执行
应用场景假设有3个不同的测试场景,分别为并发登录.核心业务.可靠性测试,3个场景有先后执行顺序.由于白天测试机器另有用处,只能在晚上进行性能测试,这时我们的期望是能否把测试场景都设定好之后晚上自动运行 ...
- leetcode——Implement strStr() 实现字符串匹配函数(AC)
Implement strStr(). Returns a pointer to the first occurrence of needle in haystack, or null if need ...
- android.view.View
* This class represents the basic building block for user interface components. A View * occupies a ...
- jQuery 1.x and 2.x , which is better?
1. jQuery 1.x和2.x的区别 或者可以说是jQuery 2.x有什么新特征? jQuery官方发布2.x原话 不再支持IE6/7/8,如果在IE9/10里只用“兼容性视图”模式也将会受到影 ...
- POJ3694 Network —— 边双联通分量 + 缩点 + LCA + 并查集
题目链接:https://vjudge.net/problem/POJ-3694 A network administrator manages a large network. The networ ...
- IE、W3C两种CSS盒子模型
利用CSS来布局页面布局DIV有点逻辑性!重点理解盒子模型,标准流和非标准流的区别,还有定位原理!把这3个攻破了,就非常简单了!多实践多参考!最后就是兼容问题了,在实践中自然就有经验了!这些兼容技巧都 ...