三等分数组

输入数组长度和具体数值,使其三等分,不存在平分方案输出0
# n=int(input())
m=list(map(int,input().split()))
sum1=sum(m)

def t(a,b,c,l,s):
    if len(l)==0:
        if sum(a)==sum(b)==sum(c):
            global f
            f=[]
            f.append(a)
            f.append(b)
            f.append(c)
            return True
        else:
            return False
    if (sum(a)<=s and t(a+[l[0]],b,c,l[1:],s))&nbs***bsp;(sum(b)<=s and t(a,b+[l[0]],c,l[1:],s))&nbs***bsp;(sum(c)<=s and t(a,b,c+[l[0]],l[1:],s)):
        return True
    else:
        return False
a=[]
b=[]
c=[]
if (sum1%3)!=0:
    print(0)
else:
    if t(a,b,c,m,sum1//3):
        print(f)
    else:
        print(0)


全部评论
6 (7 7 1 6 6 1)过不了
点赞 回复 分享
发布于 2023-03-30 23:22 北京

相关推荐

01-29 16:08
已编辑
华南农业大学 Java
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务