def perm(n, k): if k == n: print(p) return else: for i in range(k, n): p[k], p[i] = p[i], p[k] perm(n, k+1) p[k], p[i] = p[i], p[k] p = [1, 2, 3] perm(3, 0) def f(n, m, k): if n == k: print(p) else: for i in range(m): if u[i] == 0: u[i] = 1 p[k] = arr[i] f(n, m, k+1) u[i] = 0 p = [0] * 3 arr = [1,2,3,4,5] u = [0] * len(arr) # mPn, 몇번째 수인지 f(3, 5, 0)