# 35. 考古学家考古问题

35 35-1

const readline = require('readline');
const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

function dfs(arr, depth, path, used, res) {
    if (depth === arr.length) {
        res.push([...path]);
        return;
    }
    for(let i=0; i<arr.length; i++) {
        if(used[i]) continue;
        if (i>0 && arr[i] === arr[i-1] && !used[i-1]) {
            continue;
        }
        path.push(arr[i]);
        used[i] = true;
        dfs(arr, depth+1, path, used, res);
        path.pop();
        used[i]=false;
    }
}

rl.on('line', (line) => {
    let n = line.split(line);
    rl.on('line', (line) => {
        let arr = line.split(' ');
        let res = [];
        arr.sort();
        let path = [];
        let used = new Array(n).fill(false);
        dfs(arr, 0, path, used, res);
        for(let v of res) {
            console.log(v.join(''))
        }
    });
});
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38