题解 | #火车进站#

火车进站

https://www.nowcoder.com/practice/97ba57c35e9f4749826dc3befaeae109

a = int(input().strip())
b = list(map(str,input().strip().split(" ")))
resault = []
def dfs(input1,wait1,output1):
    if len(output1) == a:
        resault.append(output1)
    if input1:
        dfs(input1[1:],wait1+[input1[0]],output1)
    if wait1:
        dfs(input1,wait1[:-1],output1+wait1[-1])
dfs(b,[],'')
for i in sorted(resault):
    for j in i:
        print(j,end=" ")
    print()


全部评论

相关推荐

评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务