RT,以下是代码
#include<bits/stdc++.h>
using namespace std;
int n,m,a[25];
int tot,to[25],nxt[25],head[25],cnt;
bool vis[25];
void adde(int u,int v){
tot++;
to[tot]=v;
nxt[tot]=head[u];
head[u]=tot;
}
void dfs(int x){
vis[x]=1;
for(int i=head[x];i;i=nxt[i]){
if(!vis[to[i]]) dfs(to[i]);
}
for(int i=0;i<n;i++){
if(x&(1<<i) && !vis[x-(1<<i)]) dfs(x-(1<<i));
}
}
int main(){
cin >> n >> m;
for(int i=1;i<=m;i++){
cin >> a[i];
adde(a[i],a[i]^((1<<n)-1));
}
for(int i=1;i<=m;i++){
if(!vis[a[i]]){
vis[a[i]]=1;
dfs(a[i]^((1<<n)-1));
cnt++;
}
}
cout << cnt;
return 0;
}