AcWing 420. 火星人
原题链接
中等
作者:
我要出去乱说
,
2021-01-28 23:37:58
,
所有人可见
,
阅读 250
STL大法
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 10010;
int n, m;
int w[N];
int main()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++ ) cin >> w[i];
while (m -- )
{
next_permutation(w + 1, w + n + 1);
//手动实现next-permutation函数
//int k = n;
// while (w[k - 1] > w[k]) k -- ;
// int t = k;
// while (w[t + 1] > w[k - 1]) t ++ ;
// swap(w[k - 1], w[t]);
// reverse(w + k, w + n + 1);
}
for (int i = 1; i <= n; i ++ ) cout << w[i] << ' ';
cout << endl;
return 0;
}