You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
759 B

#include <bits/stdc++.h>
using namespace std;
const int N = 110;
vector<int> a;
int st[N];
int n, r;
/**
测试用例:
3 2
1 2
1 3
2 1
2 3
3 1
3 2
*/
void dfs(int step, int m) {
if (m == r) {
for (int i = 0; i < a.size(); i++) printf("%d ", a[i]);
printf("\n");
return;
}
if (step == n + 1)return;
//每个数字都可尝试放进当前箱子
for (int i = 1; i <= n; i++) {
//如果没有用过
if (!st[i]) {
//选择
a.push_back(i);
st[i] = true;
dfs(step + 1, m + 1);
st[i] = false;
a.pop_back();
}
}
}
int main() {
cin >> n >> r;
dfs(1, 0);
return 0;
}