题目103:考察具有特殊子集和性质的集合
本帖最后由 欧拉计划 于 2016-8-18 23:13 编辑Special subset sums: optimum
Let S(A) represent the sum of elements in set A of size n. We shall call it a special sum set if for any two non-empty disjoint subsets, B and C, the following properties are true:
S(B) ≠ S(C); that is, sums of subsets cannot be equal.
i. If B contains more elements than C then S(B) > S(C).
ii. If S(A) is minimised for a given n, we shall call it an optimum special sum set. The first five optimum special sum sets are given below.
n = 1: {1}
n = 2: {1, 2}
n = 3: {2, 3, 4}
n = 4: {3, 5, 6, 7}
n = 5: {6, 9, 11, 12, 13}
It seems that for a given optimum set,, the next optimum set is of the form , where b is the "middle" element on the previous row.
By applying this "rule" we would expect the optimum set for n = 6 to be A = {11, 17, 20, 22, 23, 24}, with S(A) = 117. However, this is not the optimum set, as we have merely applied an algorithm to provide a near optimum set. The optimum set for n = 6 is A = {11, 18, 19, 20, 22, 25}, with S(A) = 115 and corresponding set string: 111819202225.
Given that A is an optimum special sum set for n = 7, find its set string.
NOTE: This problem is related to Problem 105 and Problem 106.
题目:
用 S(A) 表示一个包含 n 个元素的集合 A 的元素之和。如果该集合的任意两个非空不相交子集满足以下性质,我们将其称为一个特殊和集。
S(B) ≠ S(C); 也就是两个子集的和不相等。
i. 如果 B 中的元素数量多于 C,则 S(B) > S(C)。
ii. 如果对于给定的 n,S(A) 取到最小,我们称其为一个最优特殊和集。前五个最优特殊和集如下:
n = 1: {1}
n = 2: {1, 2}
n = 3: {2, 3, 4}
n = 4: {3, 5, 6, 7}
n = 5: {6, 9, 11, 12, 13}
看起来,似乎对于一个给定的最优特殊和集,,下一个最优特殊和集具有如下形式:,其中 b 是前一个集合的“中间”元素。
如果使用这条“规则”,我们认为对于 n=6 的最优特殊和集将是 A = {11, 17, 20, 22, 23, 24},S(A)=117。但是,这其实并不是最优特殊和集,因为我们只是使用一个算法得到了以近似最优的集合。对于 n=6 的最优集合应该是 A = {11, 18, 19, 20, 22, 25},S(A)=115,其对应的字符串为:111819202225。
A 为 n=7 的最优特殊和集,求其对应的字符串。
注意:该题目与题目105, 106 相关。
这题好渣,答案就是根据n=6求出的可能最优解{:5_90:}
20313839404245 255
from itertools import combinations
ms = 300
for L in [ for a1 in range(19,24) for a2 in range(a1+1, 34) for a3 in range(a2+1,a1+a2) for a4 in range(a3+1,a1+a2) for a5 in range(a4+1,a1+a2+a3-a4) for a6 in range(a5+1, a1+a2+a3-a5) for a7 in range(a6+1,a1+a2+a3+a4-a5-a6)]:
sums = set()
ok = True
for s in :
if s in sums:
ok = False
break
else:
sums.add(s)
if not ok:
continue
for s in :
if s in sums:
ok = False
break
else:
sums.add(s)
if not ok:
continue
s = sum(L)
if s <= ms:
ms = s
print("".join(), s)
页:
[1]