代码
#include <iostream>
using namespace std;
void print(int n, int state){
int cur = 1;
for(int i = 0; i < n; i++){
if((state >> i) & 1){
cout << cur << " ";
}
cur++;
}
cout << endl;
}
void f(int cur, int n, int state){
if(cur == n){
print(n, state);
return;
}
f(cur+1, n, state | (1 << cur));
f(cur+1, n, state);
}
int main()
{
int n;
cin >> n;
f(0, n, 1 << n);
return 0;
}