b942: 轟轟島
http://zerojudge.tw/ShowProblem?problemid=b942
窮舉法
- while True:
- try:
- X = [int(x) for x in input().split()]
- X = sorted(X)[::-1] # a little faster in big-to-small order
- N = len(X)
- half = sum(X)/2
- area = 0
- for decimal in range(2**N):
- binary = bin(decimal)[2:]
- one_side = 0
- for i in range(len(binary)):
- one_side += X[i] * int(binary[i])
- if one_side == half:
- area = one_side**2
- break
- area = max(area, one_side * (sum(X) - one_side))
- print(area)
- except:
- break
:cry:
O(2**N) is too big