偷拿itertools来改,9位数跑完大约7~8秒,供参考
def creator(num):
ans = list()
pools = [x for x in range(1,10)]
for n in range(num):
result = [[]]
for i in range(n+1):
result = [x+[y] for x in result for y in pools if y not in x]
for res in result:
ans.append(sum([k * (10**j) for j, k in enumerate(res)]))
ans.sort()
print(*ans)
if __name__ == '__main__':
creator(int(input()))