题解 | #数组分组#

数组分组

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

全部评论

相关推荐

zYvv:双一流加大加粗再标红,然后广投。主要是获奖荣誉不够,建议开始不用追求大厂,去别的厂子刷下实习。
点赞 评论 收藏
分享
Java抽象带篮子:简历怎么写可以看看我发的帖子,你的第一个是实习经历吗?那怎么写的是你的第一个练手项目呢?简历写的怎么样直接投小厂面试一下就知道了
没有实习经历,还有机会进...
点赞 评论 收藏
分享
测试糕手手:社会第一课,随便吹牛逼,直接说四个月,别老实。老实人只会被欺负
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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