AcWing 1537. 递归实现排列类型枚举 II
原题链接
简单
作者:
daijie
,
2021-03-19 14:16:41
,
所有人可见
,
阅读 244
#include <iostream>
#include <algorithm>
using namespace std;
const int N = 15;
int a[N];
bool vis[N];
int n;
vector<int> res;
void dfs(int u)
{
if(u == n)
{
for(auto i : res)
{
printf("%d ", i);
}
puts("");
return ;
}
for(int i = 0; i < n; i ++)
{
if(vis[i] || (i && a[i] == a[i - 1] && !vis[i - 1]))
continue;
vis[i] = true;
res.push_back(a[i]);
dfs(u + 1);
res.pop_back();
vis[i] = false;
}
}
int main()
{
cin >> n;
for(int i = 0; i < n; i ++) cin >> a[i];
sort(a, a + n);
dfs(0);
return 0;
}