题解 | #数组分组#

数组分组

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

全部评论

相关推荐

07-02 10:39
门头沟学院 Java
Steven267:说点真实的,都要秋招了,还没有实习,早干嘛去了,本来学历就差,现在知道急了,而且你这个简历完全可以写成一页,劣势太大了,建议转测试
点赞 评论 收藏
分享
想按时下班的大菠萝在...:隔壁学校的,加油多投, 实在不好找可以下个学期开学找,把算法八股准备好,项目有空再换换
投了多少份简历才上岸
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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