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.

36 lines
693 B

#include <bits/stdc++.h>
using namespace std;
const int N = 10010;
int n, m;
int a[N];
/*
5
3
1 2 3 4 5
答案
1 2 4 5 3
变化过程
(1) 1 2 3 5 4
(2) 1 2 4 3 5
(3) 1 2 4 5 3
*/
int main() {
cin >> n >> m;
for (int i = 1; i <= n; i++) cin >> a[i];
while (m--) next_permutation(a + 1, a + 1 + n); // 输入数据保证这个结果不会超出火星人手指能表示的范围。
/*
int a[4] = {1, 2, 3, 4};
sort(a, a + 4);
do {
for (int i = 0; i < 4; i++) cout << a[i] << " ";
cout << endl;
} while (next_permutation(a, a + 4));
*/
for (int i = 1; i <= n; i++) printf("%d ", a[i]);
return 0;
}