题解 | #数组分组#
数组分组
https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86
def dfs(list_other, list_3, list_5):
if not list_other:
return sum(list_3) == sum(list_5)
return dfs(list_other[1:], list_3 + [list_other[0]], list_5) or dfs(list_other[1:], list_3, list_5 + [list_other[0]])
list_5 = []
list_3 = []
list_other = []
n = int(input())
nums = list(map(int,input().split()))
for num in nums:
if num % 5 == 0:
list_5.append(num)
elif num % 3 == 0:
list_3.append(num)
else:
list_other.append(num)
if dfs(list_other, list_3, list_5):
print("true")
else:
print("false")
查看18道真题和解析