递归搜索(dfs暴搜)的时间复杂度分析
根据搜索树判别, 本题中是一个完全二叉树, 因此在2 * n级别, 可能还要×一个n
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 25;
bool st[N];
int n;
void dfs(int h, bool choose){
if(h == n){
for(int i = 1; i <= n; i++){
if(st[i]) printf("%d ", i);
}
puts("");
return;
}
st[h + 1] = true;
dfs(h + 1, true);
st[h + 1] = false;
dfs(h + 1, false);
st[h + 1] = false;
}
int main(){
cin >> n;
dfs(0, false);
return 0;
}