题解 | #数组分组#

数组分组

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

全部评论

相关推荐

hwwhwh:同双非,有大厂实习其实也没啥用,主要看运气,等就行了
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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