题解 | #24点游戏算法#

24点游戏算法

http://www.nowcoder.com/practice/fbc417f314f745b1978fc751a54ac8cb

def fun(num_list, target): if len(num_list) == 1: return num_list[0] == target else: for i in range(len(num_list)): list1 = num_list[:i] + num_list[i+1:] n = num_list[i] if fun(list1, target + n) or fun(list1, target - n) or fun(list1, target * n) or fun(list1, target / n): return True else: return False

num_list = [int(i) for i in input().split()] if fun(num_list, 24): print('true') else: print('false')

全部评论

相关推荐

牛客21331815...:像我一投就pass,根本不用焦虑泡池子
点赞 评论 收藏
分享
后端转测开第一人:双非本 没大厂实习 后端肯定没机会了 直接转测开吧
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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