半年前做的一道题现在还是不会

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的更多相关文章

  1. [开发笔记] Graph Databases on developing

    TimeWall is a graph databases github It be used to apply mathematic model and social network with gr ...

  2. Introduction to graph theory 图论/脑网络基础

    Source: Connected Brain Figure above: Bullmore E, Sporns O. Complex brain networks: graph theoretica ...

  3. POJ 2125 Destroying the Graph 二分图最小点权覆盖

    Destroying The Graph Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 8198   Accepted: 2 ...

  4. [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), ...

  5. [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), ...

  6. [LeetCode] Clone Graph 无向图的复制

    Clone an undirected graph. Each node in the graph contains a label and a list of its neighbors. OJ's ...

  7. 讲座:Influence maximization on big social graph

    Influence maximization on big social graph Fanju PPT链接: social influence booming of online social ne ...

  8. zabbix利用api批量添加item,并且批量配置添加graph

    关于zabbix的API见,zabbixAPI 1item批量添加 我是根据我这边的具体情况来做的,本来想在模板里面添加item,但是看了看API不支持,只是支持在host里面添加,所以我先在一个ho ...

  9. Theano Graph Structure

    Graph Structure Graph Definition theano's symbolic mathematical computation, which is composed of: A ...

随机推荐

  1. DevOps知识地图实践指南

    DevOps知识地图   DevOps方法论的主要来源是Agile, Lean 和TOC, 独创的方法论是持续交付. DevOps经典图书: * <DevOps实践指南> * <持续 ...

  2. xmlSpy套件(Altova MissionKit 2016)的Ollydbg调试过程及破解

    最近工作需要用到XML处理软件,网上找到Altova MissionKit 2016( 包含了XmlSpy.MapForce.StyleVision.UModel.DatabaseSpy等工具),用了 ...

  3. Command Analyze failed with a nonzero exit code

    在运行RN项目的时候,报 Command Analyze failed with a nonzero exit code ,试着将build System 修改下

  4. bootstrap是什么

    Bootstrap,来自 Twitter,是目前最受欢迎的前端框架. Bootstrap 是基于 HTML.CSS.JAVASCRIPT 的,它简洁灵活,使得 Web 开发更加快捷. 本教程将向您讲解 ...

  5. c#代码分析

    代码分析是在一个IT行业计算机程序员必须要具有的基本专业技能,在了解一定的专业基础之上去看懂别人编写的代码,分析别人代码实现的功能,以及基本的维护和扩展测试.不同的人有不同的代码风格,要使自己的能要别 ...

  6. Echarts学习求教

    有没有人用过百度的Echarts?刚开始接触,下面这段代码怎么理解啊,新手求指教: myChart.showLoading();$.get('data/asset/data/les-miserable ...

  7. beta阶段测试基本概况对应机型硬件信息

    机型测试概况 测试结果 测试终端数 品牌分布分析 系统分布分析 分辨率分布 未执行 1 联想 4.0.3 480*800 安装失败 1 联想 4.2.1 480*854 通过 119 华为, 三星, ...

  8. Markdown页内跳转实现方法

    目录 Markdown页内跳转实现方法 HTML锚点跳转 生成目录 Markdown页内跳转实现方法 [时间:2017-02] [状态:Open] [关键词:markdown,标记语言,页内跳转,ht ...

  9. java — 静态绑定和动态绑定

    绑定:一个方法的调用与方法所在的类关联起来.java中的绑定分为静态绑定和动态绑定,又被称作前期绑定和后期绑定. 静态绑定:(final.static.private)在程序执行前已经被绑定,也就是说 ...

  10. 我的software

    每个学计算机软件的同学都有可能经历以下的情况: 1.  哎,我家电脑开不了机了,来帮帮忙 2.  我耳机坏了,你给修修吧 3.  你能换手机屏不 4.  过来看下,我的Word打不开了 等等等等 这些 ...