使用stl自带函数实现全排列

2021/4/11 10:29:30

本文主要是介绍使用stl自带函数实现全排列,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

除了使用dfs实现全排列外的另一个简单方法,但是时间复杂度比较高,同时新单词为permutation//排列、组合、置换
举例:输出3的全排列

#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <string>
using namespace std;


int main(){
    int a[3]={1,2,3};
    do{
        for(int i=0;i<3;i++){
            cout<<a[i]<<" ";

        }cout<<endl;
    }while (next_permutation(a,a+3));
    return 0;
}


这篇关于使用stl自带函数实现全排列的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!


扫一扫关注最新编程教程