模版1
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
int b[100];
cin>>n;
for(int i=0; i<=n; i++)b[i]=0;
while(b[0]==0){
for(int i=1; i<=n; i++)cout<<b[i];
cout<<"\n";
int j=n;
while(b[j]==1)
j--;
b[j]++;
for(int i=j+1; i<=n; i++)b[i]=0;
}
return 0;
}
模版2
#include<bits/stdc++.h>
using namespace std;
int a[10];
void print_subset(int n)
{
for(int i=0; i<(1<<n); i++){
for(int j=0; j<n; j++)
if(i&(1<<j))
cout<<a[j]<<" ";
cout<<endl;
}
}
int main()
{
int n;
cin>>n;
for(int i=0; i<n; i++)a[i]=i+1;//初始化数组
print_subset(n);
return 0;
}
标签:std,二进制,模版,namespace,int,枚举,using,include
From: https://www.cnblogs.com/tflsnoi/p/16947251.html