|
|
back to boardPython -- what's wrong with my code? Posted by Nin_Jar 22 May 2017 14:54 import sys nums = map(int, sys.stdin.read().split()) length = nums.pop(0) result = sum_value = sum(nums) def calc(deep, total=0, ignore=[]): global result for i in range(length): if i in ignore: continue t = total + nums[i] if deep > 0: ignore.append(i) calc(deep - 1, t, ignore) else: diff = abs(sum_value - t * 2) if result > diff: result = diff if result == 0: break for i in range(length / 2): calc(i) if result == 0: break print result Re: Python -- what's wrong with my code? Try to use itertools or just bitmasks. (I can't understand your code. I got my AC just iterating through all numbers 1...2^N-1) |
|
|