第二题 from collections import defaultdict words = input().split() N = len(words) d = defaultdict(int) head = defaultdict(set) for e in words: head[e[0]].add(e[-1]) tmp = e[0] + e[-1] d[tmp] += 1 res = False def fun(startC, word, num): global res if num == 0: res = True return if res == True: return for c in head[word[1]]: if num == 1 and c != startC: continue tmp = word[1] + c if d[tmp] > 0: d[tmp] -= 1 fun(startC, tmp, num - 1) d[tmp] += 1 tmp = words[0][0] + words[0][-1] d[tmp] -= 1 fun(words[0][0],tmp,N-1) if res: print("true") else: print("false")
点赞 8

相关推荐

03-17 15:08
已编辑
腾讯_后端开发(准入职员工)
点赞 评论 收藏
分享
点赞 评论 收藏
分享
牛客网
牛客企业服务