题解 | #火车进站#
火车进站
https://www.nowcoder.com/practice/97ba57c35e9f4749826dc3befaeae109
lst = [] def f(wait,stack,out): if wait: f(wait[1:],stack+[wait[0]],out) if stack: f(wait,stack[:-1],out+[stack[-1]]) if not wait and not stack: lst.append(' '.join(map(str,out))) N = int(input()) ls = list(map(int,input().split())) f(ls,[],[]) lst.sort() for i in lst: print(i)