题解 | #24点游戏算法#
24点游戏算法
https://www.nowcoder.com/practice/fbc417f314f745b1978fc751a54ac8cb
def f(nums,target): if (len(nums) == 1): return nums[0] == target for i in range(len(nums)): c = nums[i] # 当前数字 tmp = nums[:i] + nums[i+1:] # 列表中的其他数字 if f(tmp,target+c) or f(tmp,target-c) or f(tmp,target*c) or f(tmp,target/c): return True return False while True: try: nums = list(map(int,input().split())) if f(nums,24): print('true') else: print('false') except: break