题解 | #数组分组#
数组分组
https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86
from itertools import combinations n = int(input()) l = [int(i) for i in input().split()] a5, b3, rest = [],[],[] for i in l: if i%5 == 0: a5.append(i) elif i%3 == 0: b3.append(i) else: rest.append(i) valid = False if rest == [] and sum(a5) == sum(b3): valid = True for i in range(len(rest)): for c in combinations(rest,i): if sum(a5) + sum(c) == sum(l) - sum(a5) - sum(c): valid = True break print('true' if valid else 'false')感觉用combinations像是在偷懒,看个乐吧