题目描述
blablabla
算法1
(暴力枚举) $O(n^2)$
blablabla
时间复杂度
参考文献
Python 代码
import sys
n = int(input())
res = []
stack = [0] * (n+1)
def dfs(top, x):
global cnt
if cnt >= 20: return
if x > n and top == 0: # 全部出栈 栈中无元素
tmp = ""
for i in range(n):
tmp += str(res[i])
cnt += 1
print(tmp)
return
if top:
cur = stack[top]
res.append(cur)
dfs(top - 1, x) # 出栈
res.pop()
stack[top] = cur
if x <= n:
stack[top + 1] = x
dfs(top + 1, x + 1) #x 进栈
if __name__ == "__main__":
cnt = 0
dfs(0,1)