dfs递归枚举
#include<iostream>
using namespace std;
const int N =16;
int state[N]; //0表示未考虑,1表示选择,2表示未选择.
int n;
void dfs(int u){
if(u>n){
for(int i=1;i<=n;i++){
if(state[i] == 1)
printf("%d ", i);
}
cout<<"\n";
return ;
}
state[u] = 2; //不选择
dfs(u+1);
state[u] =0;
state[u] = 1; //选择
dfs(u+1);
state[u] =0;
}
int main(){
cin>>n;
dfs(1);
return 0;
}