题解 | #数组分组#

数组分组

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

全部评论

相关推荐

10-14 10:56
已编辑
长沙学院 嵌入式软件开发
痴心的00后拿到了ssp:hr面挂了,无所谓了反正不去😃
点赞 评论 收藏
分享
点赞 收藏 评论
分享
牛客网
牛客企业服务