题解 | #数组分组#

数组分组

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

n=input()
s=list(map(int,input().split()))
five=[]
three=[]
other=[]
for i in s:
    if i%5==0:
        five.append(i)
    elif i%3==0:
        three.append(i)
    else:
        other.append(i)
diff=abs(sum(five)-sum(three))

def func(s,a,b):
    if len(s)==0:
        if abs(sum(a)-sum(b))==diff:
            return True
    else:
        if func(s[1:],a+[s[0]],b) or func(s[1:],a,b+[s[0]]):
            return True

print('true' if func(other,[],[]) else 'false')

全部评论

相关推荐

缒梦&独舞:这家公司是这样的,去年给我实习offer了,不过也是面着玩儿的,他周六还要去做公益志愿活动
点赞 评论 收藏
分享
评论
1
收藏
分享

创作者周榜

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