题解 | #火车进站#
火车进站
https://www.nowcoder.com/practice/97ba57c35e9f4749826dc3befaeae109
import sys n = int(input()) trains = input().split() allout = [] def dig(station,notin,outlist): #in if len(notin) >0: station_add = station+[notin[0]] dig(station_add, notin[1:],outlist) if len(station)>0: thisout = station.pop() outlist_add = outlist+[thisout] dig(station, notin, outlist_add) if len(outlist)==n: allout.append(outlist) dig([],trains,[]) allout = sorted(allout) for i in allout: print(' '.join(i))