题目描述
P1088 [NOIP2004 普及组] 火星人
next_permutation
这里介绍两个计算序列全排列的函数:
- next_permutation(a,a+n)
- prev_permutation(start,end)
参数为数组的首尾
 意在获取当前全排列的下(上)一个全排序
 上下怎么理解呢?
 例如1-3的全排列为
123
132
213
231
312
321
132就是123的下一个全排列,反之为上一个全排列
 这道题也没什么好说的,精准考察了这一函数的使用
#include <bits/stdc++.h>
using namespace std;
const int N = 1e4 + 10;
int a[N];
int main() {
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	
	int idx = m;
	while (idx--) {
		next_permutation(a, a+n);
	}
	
	for (int i = 0; i < n; i++) printf("%d ", a[i]);
	
	return 0;
} 









