题解 | #火车进站#
火车进站
https://www.nowcoder.com/practice/97ba57c35e9f4749826dc3befaeae109
n = int(input())
L = list(map(int, input().split()))
ans = []
def func(wait, stack, out):
if len(out) == n:
ans.append(" ".join(map(str, out)))
if len(wait) != 0:
func(wait[1:], stack + [wait[0]], out)
if len(stack) != 0:
func(wait, stack[:-1], out + [stack[-1]])
func(L, [], [])
for item in sorted(ans):
print(item)
查看10道真题和解析