C++ 代码
#include<bits/stdc++.h>
using namespace std;
int arr[25];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
memset(arr, 1, sizeof(arr));
int n, m;
cin >> n >> m;
for (int i = 0; i < m; ++i) {
arr[i] = 0;
}
do {
for (int i = 0; i < n; ++i) {
if (arr[i] == 0) {
cout << i + 1 << ' ';
}
}
cout << '\n';
} while (next_permutation(arr, arr + n));
return 0;
}