codeforces485C(位运算->建图)

这个题比较套路,貌似cls给noip模拟赛出过相同的题。。orznoip什么时候这么难了啊qaq

然后这个关键问题就在建图了,由于直接连边数太多,必须考虑将边的规模压缩。。

然后方法就是对每个数i向去掉其中一个1后的数连边(这里都是单向边),最多n条边。。然后如果出现了数组中存在的数。。那么就向反转后的数连边。。

然后发现这么连可以将x&y的点都给连起来。。而那些不在一个块上的是连不到的。。

然后直接乱搜就行了。。复杂度O(n*2^n)

其实最近出了挺多这样的题的。。上次NCPC的D也是一样。。

所以建图可以考虑这么一个思路,于只对某位做位运算后得到的点连边。。



/**
 *          ┏┓    ┏┓
 *          ┏┛┗━━━━━━━┛┗━━━┓
 *          ┃       ┃  
 *          ┃   ━    ┃
 *          ┃ >   < ┃
 *          ┃       ┃
 *          ┃... ⌒ ...  ┃
 *          ┃              ┃
 *          ┗━┓          ┏━┛
 *          ┃          ┃ Code is far away from bug with the animal protecting          
 *          ┃          ┃   神兽保佑,代码无bug
 *          ┃          ┃           
 *          ┃          ┃        
 *          ┃          ┃
 *          ┃          ┃           
 *          ┃          ┗━━━┓
 *          ┃              ┣┓
 *          ┃              ┏┛
 *          ┗┓┓┏━━━━━━━━┳┓┏┛
 *           ┃┫┫       ┃┫┫
 *           ┗┻┛       ┗┻┛
 */ 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 5000005
#define nm 5000005
#define pi 3.1415926535897931
const ll inf=1000000007;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}


int a[NM],n,m,tot,s;
bool v[NM],b[NM];
void dfs(int x){
    if(v[x])return;
    v[x]++;
    if(b[x])dfs(tot-x);
    inc(i,1,n)if(succ(i-1)&x)dfs(succ(i-1)^x);
}

int main(){
    n=read();m=read();tot=succ(n)-1;
    inc(i,1,m)b[a[i]=read()]++;
    inc(i,1,m)if(!v[a[i]])dfs(a[i]),s++;
    return 0*printf("%d\n",s);
}





C. AND Graph
time limit per test
4 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You are given a set of size m

with integer elements between 0 and 2n1 inclusive. Let's build an undirected graph on these integers in the following way: connect two integers x and y with an edge if and only if x&y=0. Here &

is the bitwise AND operation. Count the number of connected components in that graph.

Input

In the first line of input there are two integers n

and m ( 0n22, 1m2n

).

In the second line there are m

integers a1,a2,,am ( 0ai<2n) — the elements of the set. All ai

are distinct.

Output

Print the number of connected components.

Examples
Input
Copy
2 3
1 2 3
Output
Copy
2
Input
Copy
5 5
5 19 10 20 12
Output
Copy
2
Note

Graph from first sample:

Graph from second sample:


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值