n个数中取r个数的全排列 python

a = [0 for i in range(20)] visit = [0 for i in range(20)] n,r = map(int,input().split())def Print(): for i in range(1,r+1): print(a[i],end=' ') print()def dfs(k): for i in range(1,n+1): if visit[i] != 1: a[k] = i visit[i] = 1 if k == r: Print() else: dfs(k+1) visit[i] = 0dfs(1)

    推荐阅读