题目描述
blablabla
笔记
算法1
C++ 代码
#include <iostream>
#include<cstring>
#include <algorithm>
using namespace std;
const int s = 10010;
int ss[s];
int n, m;
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> ss[i];
for (int i = 0; i < m; i++)
next_permutation(ss, ss + n);
for (int i = 0; i < n; i++)
cout << ss[i] << " ";
return 0;
}
算法2
C++ 代码
#include <iostream>
#include<cstring>
#include <algorithm>
using namespace std;
const int s = 10010;
int ss[s];
int n, m;
int main()
{
cin >> n >> m;
for (int i = 0; i < n; i++)
cin >> ss[i];
for (int i = 0; i < m; i++)
{
int a = n - 1;
while (ss[a - 1]>ss[a])
a--;
int b = a;
while (ss[b + 1]>ss[a - 1])
b++;
swap(ss[b], ss[a - 1]);
reverse(ss + a, ss + n);
}
for (int i = 0; i < n; i++)
cout << ss[i] << " ";
return 0;
}