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 ...
 
随机推荐
- sql文件或连接数据库反向生成pdm文件
			
1. File -> Reverse Engineer -> Database 2.选择sql数据库类型 mysql / sqlserver /oracle 3.using script ...
 - Bash 中常见的字符串操作
			
获取字符串长度 ${#string} MyString=abcABC123ABCabc 注意这会自动去掉字符串结尾处的空格,如果在字符串中包含空格(开头.中间或结尾),就需要使用引号把字符串包裹起来: ...
 - 做完小程序项目、老板给我加了5k薪资~
			
大家好,我是苏南,今天要给大家分享的是最近公司做的一个小程序项目,过程中的一些好的总结和遇到的坑,希望能给其他攻城狮带来些许便利,更希望能做完之后老板给你加薪- 今天是中秋节的第一天,假日的清晨莫名的 ...
 - Windows10 家庭版 Docker的安装
			
Docker的安装 1.简介:Docker 是一个开源的应用容器引擎,让开发者可以打包他们的应用以及依赖包到一个可移植的容器中, 然后发布到任何流行的 Linux 机器上,也可以实现虚拟化.容器是完全 ...
 - 关于用tesseract和tesserocr识别图片的一个问题
			
对于像我这样初学python网络爬虫的freshman来说,软件的准备和环境的配置能让我们崩溃.其中用刚安装好的tesseract和tesserocr库测试识别验证码就是其中一例. 这里我要测试的验证 ...
 - centos7.4下Jira6环境部署及破解操作记录(完整版)
			
废话不多说,以下记录了Centos7针对Jira6的安装,汉化,破解的操作过程,作为运维笔记留存. 0) 基础环境 192.168.10.212 Centos7.4 mysql 5.6 jdk 1.8 ...
 - Nginx基于TCP/UDP端口的四层负载均衡(stream模块)配置梳理
			
通过我们会用Nginx的upstream做基于http/https端口的7层负载均衡,由于Nginx老版本不支持tcp协议,所以基于tcp/udp端口的四层负载均衡一般用LVS或Haproxy来做.至 ...
 - linux内核分析字符集实践报告
 - <构建之法>13——17章的读后感
			
第13章:软件测试 问题:对于这么多种的测试方法,怎么才能最有效的选取? 第14章:质量保证 问题:很多工程师都把大多数时间花在软件质量上.一成不变是无法创新的.如何在保证质量的情况下,又得到创新呢? ...
 - MYSQL ROW_FORMAT=Compact
			
https://dev.mysql.com/doc/refman/5.6/en/innodb-row-format-antelope.html https://docs.oracle.com/cd/E ...