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.

34 lines
609 B

#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n, k;
vector<int> path;
bool st[N];
void dfs(int step) {
if (step == k + 1) {
cout << "(";
for (int i = 0; i < path.size() - 1; ++i) {
cout << path[i] << ",";
}
cout << path.back() << ")";
return;
}
for (int i = 1; i <= n; i++) {
if (!st[i]) {
path.push_back(i);
st[i] = true;
dfs(step + 1);
st[i] = false;
path.pop_back();
}
}
}
int main() {
cin >> n >> k;
dfs(1);
return 0;
}