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.
This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
# include <bits/stdc++.h>
using namespace std ;
/*
知识点内容: STL 全排列函数详解
从n个不同元素中任取m( m≤n) 个元素, 按照一定的顺序排列起来, 叫做从n个不同元素中取出m个元素的一个排列。
当m=n时所有的排列情况叫全排列。如果这组数有n个, 那么全排列数为n!个。
文档内容参考:
https://www.cnblogs.com/aiguona/p/7304945.html
*/
using namespace std ;
int main ( ) {
int arr [ ] = { 3 , 2 , 1 } ;
cout < < " 用prev_permutation对3 2 1的全排列 " < < endl ;
do {
cout < < arr [ 0 ] < < ' ' < < arr [ 1 ] < < ' ' < < arr [ 2 ] < < ' \n ' ;
} while ( prev_permutation ( arr , arr + 3 ) ) ; ///获取上一个较大字典序排列, 如果3改为2, 只对前两个数全排列
int arr1 [ ] = { 1 , 2 , 3 } ;
cout < < " 用next_permutation对1 2 3的全排列 " < < endl ;
do {
cout < < arr1 [ 0 ] < < ' ' < < arr1 [ 1 ] < < ' ' < < arr1 [ 2 ] < < ' \n ' ;
} while ( next_permutation ( arr1 , arr1 + 3 ) ) ; ///获取下一个较大字典序排列, 如果3改为2, 只对前两个数全排列
///注意数组顺序,必要时要对数组先进行排序
return 0 ;
}