题解 | #数组分组#
数组分组
https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86
import re import sys n = int(input()) a = list(map(int, input().split())) def check(list1,list2,left): if len(left)==0: sum1 = sum(list1) sum2 = sum(list2) if sum1==sum2: return True else: return False else: this = left[0] leftnext = left[1:] if this%5==0: list1 = list1+[this] res = check(list1,list2,leftnext) elif this%3==0: list2 = list2+[this] res = check(list1,list2,leftnext) else: list1new = list1+[this] res1 = check(list1new,list2,leftnext) list2new = list2+[this] res2 = check(list1,list2new,leftnext) res = res1 or res2 return res res = check([],[],left=a) if res: print('true') else: print('false')