题解 | #数组分组#
数组分组
https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86
import sys
num = int(input().strip())
a = list(map(int,input().strip().split(" ")))
justre = False
def solve(arr1,arr2,arr3):
global justre
if not arr3:
if sum(arr1) == sum(arr2):
justre = True
else:
return 0
else:
a1 = arr3[0]
solve(arr1+[a1],arr2,arr3[1:])
solve(arr1,arr2+[a1],arr3[1:])
threearr,fivearr,otherarr = [],[],[]
for i in a:
if i%3 == 0:
threearr.append(i)
elif i%5 == 0:
fivearr.append(i)
else:
otherarr.append(i)
solve(threearr,fivearr,otherarr)
if justre:
print('true')
else:
print('false')
