}
}
}
int main() {
cin >> n;
dfs(1);
}
### 组合型DFS

* **与全排列的差别就是第二个for循环开始的位置,换句话说就是每个数该放什么位置。**
#include <bits/stdc++.h>
using namespace std;
const int N = 30;
int path[N];
int n, m;
void dfs (int u, int start ) {//u:层数 start:起始的数值
if (u > m) {
for (int i = 1; i <= m; i ++ ) {
cout << path[i] << ’ ';
}
puts(“”);
}
else {
for (int i = start; i <= n; i ++) {//
path[u] = i;//表示已经填了
dfs(u + 1, i + 1);//递归下一层
path[u] = 0;//恢复现场
}
}
}
int main () {
cin >> n >> m;
dfs(1,1); //第一层开始 且从1开始枚举
return 0;
}
### 指数DFS

* 参数 : 前u个数 选 or 不选 的
* **需要保存第x位置的状态的时候就需要用st数组来存状态**
* int st[] 0:没有遇见 1 选 2不选
#include
#include
#include
using namespace std;
const int N = 16;
int st[N];
int n;
void dfs (int u) {//u :层数
if (u > n) {//叶子结点
for (int i = 1; i <=n; i ++ ){
if (st[i] == 1) {//如果选了 就输出 1选 2不选
cout << i << ’ ';
}
}
puts(“”);
return ;
}
st [u] = 1;//选
dfs (u + 1);//递归下一层
st[u] = 0;//回溯
st[u] = 2;//不选
dfs (u+1);//递归下一层
st[u] = 0;//回溯 【恢复现场】
}
int main () {
cin >> n;
dfs(1);
return 0;
}
## 二、专题
### 烤鸡 (指数BFS)
* 每个方案有3种选择,枚举全部则有 310 种方案数

https://www