题解 | #火车进站#

火车进站

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

ln = []


def fun(station, lsin, lsout):
    if len(lsin) == 0:
        while len(station) > 0:
            lsout.append(station.pop())
        ln.append(lsout)
        return
    if len(station) == 0:
        station3 = []
        station3.append(lsin[0])
        return fun(station3, lsin[1:], lsout[:])
    station1 = station[:-1]
    station1.append(lsin[0])
    lsout1 = lsout[:]
    lsout1.append(station[-1])
    lsin1 = lsin[1:]
    fun(station1, lsin1, lsout1)
    station2 = station[:]
    station2.append(lsin[0])
    lsout2 = lsout[:]
    lsin2 = lsin[1:]
    fun(station2, lsin2, lsout2)
    station3 = station[:-1]
    lsout3 = lsout[:]
    lsout3.append(station[-1])
    lsin3 = lsin[:]
    fun(station3, lsin3, lsout3)
    return


N = int(input())
ls = input().split()
fun([], ls, [])
ln = list({tuple(i) for i in ln})
ln.sort(reverse=True)
while len(ln) > 0:
    print(" ".join(ln.pop()))

全部评论

相关推荐

蚂蚁 基架java (n+6)*16 签字费若干
点赞 评论 收藏
分享
牛客263158796号:我领羊一面后十天不挂也不推进 今天问hr说等前序的第一批意向发完看情况再看是否推进
点赞 评论 收藏
分享
评论
点赞
收藏
分享
牛客网
牛客企业服务