这道题很像我写过这篇博客的第一题:https://blog.csdn.net/weixin_43262291/article/details/90242741
如果知道如图的异或前缀的方法,那么这题就可以转而构造异或前缀和,再反向分解。
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
const int inf = 0x3f3f3f3f;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int maxn = 5e5+5;
bool vis[maxn];
int main(){
IO;
int n,x;cin>>n>>x;
vector<int>a;
vis[0] = 1;
for(int i = 1;i<1<<n;i++)if(!vis[i^x]){
a.push_back(i);
vis[i] = 1;
}
cout << a.size()<<'
';
forn(i,a.size()){
if(!i) cout <<a[i];
else cout <<(a[i]^a[i-1]);
if(i!= a.size()-1) cout <<' ';
else cout <<'
';
}
return 0;
}