题解 | #数组分组#
数组分组
https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86
n = int(input()) # 数据个数
ls = list(map(int, input().split()))
q3 = []
q5 = []
q = []
for i in ls:
if i % 3 == 0:
q3.append(i)
elif i % 5 == 0:
q5.append(i)
else:
q.append(i)
def f(three, five, other):
if len(other) == 0:
if sum(three) == sum(five):
return True
else:
return False
return f((five + [other[0]]), three, other[1:]) or f(
five, (three + [other[0]]), other[1:]
)
if f(q3, q5, q):
print("true")
else:
print("false")
CVTE公司福利 714人发布
查看1道真题和解析