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 ...
随机推荐
- 开启mac上印象笔记的代码块
Mac 印象笔记左上角菜单栏:偏好设置-->软件更新-->开启代码块 (Preferences -> Software Update -> Enable code block) ...
- Linux内核第三节 20135332武西垚
总结部分: Linux内核源代码: Arch 支持不同cpu的源代码:主要关注x86 Init 内核启动的相关代码:主要关注main.c,整个Linux内核启动代码start_kernel函数 K ...
- Windows10安装ubuntu & caffe GPU版
1.Ubuntu https://www.cnblogs.com/EasonJim/p/7112413.html https://blog.csdn.net/jesse_mx/article/deta ...
- idea 设置注释
idea和eclipse的注释还是有一些差别的. idea: 类头注释:打开file->setting->Editor->Filr and Code Templates->In ...
- git心得与总结
任何文件在Git库中都有四种状态:未跟踪状态untracked.跟踪状态tracked(未修改状态unmodified.已修改状态modified.暂存状态staged),由于文件的上述四种状态,在使 ...
- Spring框架最简单的定时任务调用
package org.jeecgframework.core.timer; import org.springframework.scheduling.annotation.Scheduled; i ...
- redi集群测试
redis集群的测试 原文:http://blog.sina.com.cn/s/blog_53b45c4d0102wg10.html 1.测试存取值 客户端连接集群redis-cli需要带上 -c ...
- [转帖]Linux的进程线程及调度
Linux的进程线程及调度 本文为作者原创,转载请注明出处:https://www.cnblogs.com/leisure_chn/p/10393707.html 本文为宋宝华<Linux的进程 ...
- From 简书 转帖一下如何安装k8s1.10 改天做下实验. https://www.jianshu.com/p/9c7e1c957752
centos7.3 kubernetes/k8s 1.10 离线安装 老菜_misa 关注 2018.04.25 23:57 字数 1243 阅读 266评论 1喜欢 3 本文介绍在centos7.3 ...
- [linux学习]sysctl 以及 net.ipv4.ip_forward
1. sysctl 命令显示 当前系统的参数配置信息 显示全部配置信息 sysctl -a 帮助信息主要如下: [root@k8s-master ~]# sysctl -help Usage: sys ...