题解 | #数组分组#

数组分组

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

import re
import sys

n = int(input())

a = list(map(int, input().split()))

def check(list1,list2,left):
    if len(left)==0:
        sum1 = sum(list1)
        sum2 = sum(list2)
        if sum1==sum2:
            return True
        else:
            return False
    else:
        this = left[0]
        leftnext = left[1:]
        if this%5==0:
            list1 = list1+[this]
            res = check(list1,list2,leftnext)
        elif this%3==0:
            list2 = list2+[this]
            res = check(list1,list2,leftnext)
        else:
            list1new = list1+[this]
            res1 = check(list1new,list2,leftnext)
            list2new = list2+[this]
            res2 = check(list1,list2new,leftnext)

            res = res1 or res2
        
        return res

res = check([],[],left=a)
if res:
    print('true')
else:
    print('false')

全部评论

相关推荐

06-26 15:33
青岛工学院 Java
积极的秋田犬要冲国企:他现在邀请我明天面试
点赞 评论 收藏
分享
不愿透露姓名的神秘牛友
07-15 17:17
听说过付费实习,没想到这么贵啊我去,要不我给你个腰子吧
哈哈哈,你是老六:这种公司一定要注意啊,不要随便签合同,只要签了后面钱可能回不来,而且你通过法律途径也弄不回
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

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