查找最大子集,以使子集中的任何两个元素之和不等于k

def nonDivisibleSubset(k, s):
    remdict={}
    result=[]
    for i in range(len(s)):
        rem=s[i]%k
        if rem not in remdict:
            remdict[rem]=[s[i]]
        else:
            remdict[rem].append(s[i])
    b=dict(sorted(remdict.items(), key= lambda x: len(x[1]), reverse=True))

k = 7 {2:[576,338,149,702,282,436],6:[496,727,209],5:[278,124],4:[410,718],1:[771,575] } 在此字典中,我只想附加键2、6、4的值,因为2 + 6!= 7和2 + 4!= 7和6 + 4!= 7

评论