题解 | #数组分组#

数组分组

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")

全部评论

相关推荐

浩浩没烦恼:一二面加起来才一个小时? 我一面就一个小时多了
点赞 评论 收藏
分享
哇哇的菜鸡oc:他这不叫校招offer,而是实习offer
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务