标准模板跑出来是什么
用标准回溯模板生成 [1, 2, 3] 的全排列。运行下面这段程序:
def perm(a):
res = []
path = []
used = [False] * len(a)
def dfs():
if len(path) == len(a):
res.append(list(path))
return
for i in range(len(a)):
if used[i]:
continue
used[i] = True
path.append(a[i])
dfs()
used[i] = False
path.pop()
dfs()
return res
r = perm([1, 2, 3])
print(str(len(r)) + "/" + ",".join(str(v) for v in r[2]))
全部评论