题解 | #数组分组#

数组分组

https://www.nowcoder.com/practice/9af744a3517440508dbeb297020aca86

import sys
num = int(input().strip())
a = list(map(int,input().strip().split(" ")))
justre = False
def solve(arr1,arr2,arr3):
    global justre
    if not arr3:
        if sum(arr1) == sum(arr2):
            justre = True
        else:
            return 0
    else:
        a1 = arr3[0]
        solve(arr1+[a1],arr2,arr3[1:])
        solve(arr1,arr2+[a1],arr3[1:])
threearr,fivearr,otherarr = [],[],[]
for i in a:
    if i%3 == 0:
        threearr.append(i)
    elif i%5 == 0:
        fivearr.append(i)
    else:
        otherarr.append(i)
solve(threearr,fivearr,otherarr)
if justre:
    print('true')
else:
    print('false')

全部评论

相关推荐

06-19 13:40
武汉大学 Java
点赞 评论 收藏
分享
06-20 17:42
东华大学 Java
凉风落木楚山秋:要是在2015,你这简历还可以月入十万,可惜现在是2025,已经跟不上版本了
点赞 评论 收藏
分享
06-05 19:46
已编辑
武汉大学 后端
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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