第二题 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

相关推荐

hwwhwh:同双非,有大厂实习其实也没啥用,主要看运气,等就行了
点赞 评论 收藏
分享
少年郎as:这不把公司名贴出来那我可要喷你了哦
点赞 评论 收藏
分享
牛客网
牛客网在线编程
牛客网题解
牛客企业服务