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 ...
随机推荐
- JVM规范系列第2章:Java虚拟机结构
本规范描述的是一种抽象化的虚拟机的行为,而不是任何一种(译者注:包括 Oracle 公司自己的 HotSpot 和 JRockit 虚拟机)被广泛使用的虚拟机实现. 记住:JVM规范是一种高度抽象行为 ...
- Js基础---红宝书读书日记(1)-------基本类型和引用类型
JS的变量可能包含两种不同数据类型的值,基本类型和引用类型; 基本类型是指简单的数据段,引用类型是指可能由多个值构成的对象; JS高级程序设计第三章介绍了变量分为 5种简单数据类型(string/nu ...
- 常用rsync命令操作梳理
作为一个运维工程师,经常可能会面对几十台.几百台甚至上千台服务器,除了批量操作外,环境同步.数据同步也是必不可少的技能.说到“同步”,不得不提的利器就是rsync.rsync不但可以在本机进行文件同步 ...
- Charles使用详解
前言: Charles是在 Mac 下常用的网络封包截取工具,在做移动开发时,我们为了调试与服务器端的网络通讯协议,常常需要截取网络封包来分析. 一.主界面介绍 二.网页抓包 启动 Cha ...
- 广商博客冲刺第六七天new
第四五天沖刺傳送門 第一版的網頁已經放到 云服務器(估計快到期了) 傳送門. (不怎么會玩服務器啊..求指教..目前問題如下: 1.我的電腦mysql密碼跟服務器的密碼不一樣..上傳的時候要把代碼里面 ...
- SpringMvc配置扫包之后,访问路径404问题解决
场景: 1. 配置了Spring和SpringMvc, Spring管理非Controller类的Bean, SpringMvc管理涉及的Controller类 2. web.xml已经配置了Spri ...
- HDU 2033 人见人爱A+B
http://acm.hdu.edu.cn/showproblem.php?pid=2033 Problem Description HDOJ上面已经有10来道A+B的题目了,相信这些题目曾经是大家的 ...
- 转帖 Oracle 主键的处理方法 http://www.cnblogs.com/Richardzhu/p/3470929.html
Oracle之主键的创建.添加.删除操作 一.创建表的同时创建主键约束 1.1.无命名 SQL> create table jack (id int primary key not null ...
- Oracle 的ORION工具简单使用
1. 下载地址: http://www.oracle.com/technetwork/cn/topics/index-088165-zhs.html 2. linux x64 还有 windows的 ...
- selenium之截图
selenium支持对当前页面保存截图,使用方法: driver.get_screenshot_as_file(file_path) 代码举例: ...... def get_screenshot(d ...