CF986C AND Graph
半年前做的一道题现在还是不会
x&y=0
意味着,x的补集的子集都是和x直接相连的
不妨令图中的点数就是2^n
那么可以直接从x^((1<<n)-1)开始记忆化爆搜,路上遇到的都是和x直接相连的
如果遇到一个在给出集合里的数t,就从这个点额外再开一层,t^((1<<n)-1)再开始爆搜
这样,如果两个点直接或者间接相连,那么一定可以从任意一个点出发搜出整个连通块,并对每个点打上标记
总共的状态数是2^22。复杂度有保证
loc只是一个理解,其实不需要
#include<bits/stdc++.h>
using namespace std;
const int N=(<<)+;
int exi[N];
bool vis[N];// zuo i youwu vis
bool has[N];// you i youwu vis
int cnt,mx,len,up;
int a[N];
int n,m;
void dfs(int x,int loc){
//cout<<x<<" now "<<cnt<<endl;
if(loc){
if(has[x]) return;
has[x]=;
if(exi[x]) {vis[exi[x]]=;dfs(a[exi[x]],);}
for(int i=;(<<i)<=x;i++){
if(x&(<<i)){
dfs(x^(<<i),);
}
}
}
else{
vis[exi[x]]=;dfs(up^x,);
}
}
int main()
{
/*lg[0]=0;
for(int i=1;i<=N-5;i++) lg[i]=(i>>(lg[i-1]+1))?lg[i-1]+1:lg[i-1];*/
scanf("%d%d",&n,&m);
for(int i=;i<=m;i++){
scanf("%d",&a[i]),exi[a[i]]=i,mx=max(mx,a[i]);
}
for(int i=;i<=;i++){
if((<<i)>mx) break;
len=i+;
}
up=(<<len)-;//cout<<" up "<<up<<endl;
for(int i=;i<=m;i++){
if(!vis[i]) {
//cout<<"here go "<<i<<" "<<a[i]<<endl;
cnt++;dfs(up^a[i],);
}
}
printf("%d",cnt);return ;
}
CF986C AND Graph的更多相关文章
- [开发笔记] Graph Databases on developing
TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...
- Introduction to graph theory 图论/脑网络基础
Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...
- POJ 2125 Destroying the Graph 二分图最小点权覆盖
Destroying The Graph Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8198 Accepted: 2 ...
- [LeetCode] Number of Connected Components in an Undirected Graph 无向图中的连通区域的个数
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- [LeetCode] Graph Valid Tree 图验证树
Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...
- [LeetCode] Clone Graph 无向图的复制
Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...
- 讲座:Influence maximization on big social graph
Influence maximization on big social graph Fanju PPT链接: social influence booming of online social ne ...
- zabbix利用api批量添加item,并且批量配置添加graph
关于zabbix的API见,zabbixAPI 1item批量添加 我是根据我这边的具体情况来做的,本来想在模板里面添加item,但是看了看API不支持,只是支持在host里面添加,所以我先在一个ho ...
- Theano Graph Structure
Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...
随机推荐
- Error【0007】:zabbix中因为curl版本过低而无法发送邮件
1. 错误背景 在centos6.5上,源码部署zabbix最新版本zabbix-3.2.14.部署后之后,在配置邮件发送报警时出错 2. 错误提示 3. 原因分析 从网上检索的结果是说,系统中的cu ...
- 画了一张基于Spring Cloud的微服务系统架构图
- Dethe is my Finaunce金融
英国诗人乔叟Dethe is my Finaunce金融 英语中“金融”在14世纪,金融计算时间价值的手段.就随机结果签约的能力.一个允许转让金融权后的清算.<Lamentation of Ma ...
- M2postmortem
设想和目标 1. 我们的软件要解决什么问题?是否定义得很清楚?是否对典型用户和典型场景有清晰的描述? 答:我们的软件主要解决信息提取的问题.定义清晰:要提取的内容包括于计算机科学相关内容的标题.作者. ...
- 《Linux内核设计与实现》第十八章学习笔记
第十八章 调试 [学习时间:1小时 总结博客时间:1小时15分] [学习内容:出现bug的原因.内核调试器gdb.使用Git进行二分查找] 内核级开发的调试工作远比用户级开发艰难,它带来的风险比用户级 ...
- Opentsdb分布式安装
Opentsdb分布式安装 --李琦 1.下载文件上传到虚拟机 -rw-r--r--. 1 root root 76793860 Apr 27 10:56 opentsdb-2.2.0.tar ...
- github学习心得
1.在GitHub上建立项目登录GitHub后,你可以在右边靠中那里找到一个按钮“New Repository”,点击过后,填入项目名称.说明和网址过后就可以创建.2.配置Git以及上传代码安装Git ...
- Leetcode——66.加一
@author: ZZQ @software: PyCharm @file: leetcode66_加一.py @time: 2018/11/29 16:07 要求:给定一个由整数组成的非空数组所表示 ...
- 通过LVM给Linux扩容
主要参考以下两篇文章: 1:https://www.cnblogs.com/sixiweb/p/3360008.html 2:https://wenku.baidu.com/view/42deee1a ...
- css3-盒模型新增属性
box-shadow:跟text-shadow类似,可多层叠加 box-shadow:[inset] x y blur [spread] color inset:投影方式,inset内投影,不加参数外 ...