点击查看代码
#include<bits/stdc++.h>
using namespace std;
const int N=7e4,p=1e9+7;
int f[N],c[100];
int nxt(int x)
{
int t=(x|(x-1))+1;
int y=t|((t&-t)/(x&-x)>>1)-1;
return y;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n;
cin>>n;
for(int i=1;i<=n;++i) cout<<'0';
cout<<'\n';
for(int i=1;i<=n;++i)
{
int j=(1<<i)-1;
for(;j<1<<n;j=nxt(j))
{
for(int k=1,l=j;k<=n;++k,l>>=1) c[k]=l&1;
for(int k=n;k;--k) cout<<c[k];
cout<<" ";
}
cout<<"\n";
}
}