题解 | #火车进站#
火车进站
https://www.nowcoder.com/practice/97ba57c35e9f4749826dc3befaeae109
# 2024年9月25日
ls = []
def f(wait,stack,out): # 找到所有的出站方案
if not wait and not stack:
ls.append(' '.join(map(str,out)))
if wait:
f(wait[1:],stack+[wait[0]],out)
if stack:
f(wait,stack[:-1],out+[stack[-1]])
N = int(input())
lst = list(map(int,input().split()))
f(lst,[],[])
ls.sort()
for i in ls:
print(i)

查看16道真题和解析
