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.
39 lines
661 B
39 lines
661 B
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
const int N = 100010;
|
|
int n, k;
|
|
vector<int> path;
|
|
bool st[N];
|
|
//5 2
|
|
void print() {
|
|
cout << "(";
|
|
for (int i = 0; i < path.size() - 1; ++i)
|
|
cout << path[i] << ",";
|
|
cout << path.back() << ")";
|
|
}
|
|
|
|
void dfs(int step) {
|
|
if (step == k + 1) {
|
|
print();
|
|
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;
|
|
}
|