三个数能排出几种顺序

👁️ 0 人浏览 💬 0 人评论 ❤️ 添加收藏

走不通就退回来,换一条再走

贪心

回溯

[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

print(len(perm([1, 2, 3])))
提交你的答案
请登录后提交答案。
去登录
代码编辑器
Ctrl + Enter 运行
本次输入:
输出:

                        
👩‍🏫
AI
💬 题目评论

全部评论