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.
52 lines
959 B
52 lines
959 B
2 years ago
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
/*
|
||
|
4
|
||
|
1 1 2 3
|
||
|
*/
|
||
|
|
||
|
const int N = 110;
|
||
|
|
||
|
// 模拟131进制
|
||
|
typedef unsigned long long ULL;
|
||
|
ULL p[N];
|
||
|
const int P = 131;
|
||
|
|
||
|
// 去重HASH表
|
||
|
unordered_set<ULL> _set;
|
||
|
|
||
|
int a[N], c[N];
|
||
|
int st[N];
|
||
|
int n;
|
||
|
void dfs(int u) {
|
||
|
if (u == n + 1) {
|
||
|
ULL x = 0;
|
||
|
for (int i = 1; i <= n; i++) x += a[i] * p[i];
|
||
|
if (_set.count(x)) return;
|
||
|
for (int i = 1; i <= n; i++) cout << a[i] << " ";
|
||
|
cout << endl;
|
||
|
_set.insert(x);
|
||
|
return;
|
||
|
}
|
||
|
for (int i = 1; i <= n; i++) {
|
||
|
if (st[i]) continue;
|
||
|
st[i] = true;
|
||
|
a[u] = c[i];
|
||
|
dfs(u + 1);
|
||
|
st[i] = false;
|
||
|
}
|
||
|
}
|
||
|
int main() {
|
||
|
cin >> n;
|
||
|
for (int i = 1; i <= n; i++) cin >> c[i];
|
||
|
puts("");
|
||
|
|
||
|
// HASH初始化
|
||
|
p[0] = 1;
|
||
|
for (int i = 1; i <= N; i++) p[i] = p[i - 1] * P;
|
||
|
|
||
|
sort(c + 1, c + 1 + n);
|
||
|
dfs(1);
|
||
|
return 0;
|
||
|
}
|