Python 代码
n = int(input())
res = [0]*n
st = [0]*n
def dfs(x):
if x == n:
print(" ".join(list(map(lambda x:str(x + 1),res))))
return
for item in range(0, n):
if st[item] == 1:
continue
res[x] = item
st[item] = 1
dfs(x + 1)
st[item] = 0
dfs(0)