Python3 代码
def dfs (u, num, st):
global n
if u > n :
for i in range (1, n+1):
print (num[i], end = " ")
print("")
else:
for i in range (1, n+1):
# print (u, i, st[i])
if st[i] == False:
st[i] = True;
num[u] = i
dfs (u + 1, num, st)
st [i] = False
n = int (input())
num = [0]*(n+1)
st = [False]*(n+1)
dfs (1, num, st)