#include<iostream>
#include<vector>
using namespace std;
int count = 0;
void myswap(int &a,int &b){
int temp=a;
a=b;
b=temp;
}
void permutations(int n,int p,vector<int> path)
{
if(p >= n)
{
for(int i = 0; i < n; i++)
{
cout<<path[i]<<" ";
}
cout<<endl;
count++;
}
else
{
for(int i = p; i < n; i++)
{
myswap(path[i],path[p]);
permutations(n,p+1,path);
swap(path[i],path[p]);
}
}
}
int main()
{
vector<int>path;
int n = 5;
for(int i = 1; i <= n; i++)
{
path.push_back(i);
}
permutations(n,0,path);
cout<<count<<endl;
return 0;
}
1--n全排列
最新推荐文章于 2020-11-22 13:15:05 发布