stdio.h
https://www.runoob.com/cprogramming/c-standard-library-stdio-h.html
math.h
其他
1.全排列
原文章:https://www.cnblogs.com/aiguona/p/7304945.html
头文件:#include<algorithm>
#include <iostream>
#include <algorithm>
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;
}
本文介绍了使用C++标准库中的next_permutation和prev_permutation函数实现数组元素的全排列。通过具体示例展示了如何利用这些函数来生成所有可能的排列顺序。
729

被折叠的 条评论
为什么被折叠?



