回溯
#include <iostream>
using namespace std;
const int N = 16;
bool record[N];
void selection(int start, int end) {
if(start>end){ //到达上届
for(int i = 1;i <= end;i++){
if(record[i]) cout<<i<<" ";
}
cout<<endl;
return;
}
record[start] = true; //选
selection(start + 1,end);
record[start] = false; //不选
selection(start + 1,end);
}
int main(){
int n = 0;
cin>>n;
selection(1,n);
return 0;
}
标签:selection,end,int,start,92,Acwing
From: https://www.cnblogs.com/poteitoutou/p/17096025.html