发布网友 发布时间:2022-04-23 12:06
共3个回答
热心网友 时间:2023-10-12 21:28
l = [2,3,4,5,6,7,8,10,12,13,23,34,56]
def combination(l, n):
l = list(sorted(filter(lambda x: x <= n, l)))
combination_impl(l, n, [])
def combination_impl(l, n, stack):
if n == 0:
print(stack)
return
for i in range(0, len(l)):
if l[i] <= n:
stack.append(l[i])
combination_impl(l[i + 1:], n - l[i], stack)
stack.pop()
else:
break
combination(l, 22)
热心网友 时间:2023-10-12 21:28
L=[2,3,4,5,6,7,8,10,12,13,23,12,34,56]
d={}
n=len(L)
for i in range(n):
s=i+1
for s in range(s,n):
if L[i]+L[s]==22:
#第几位和第几位组合
print(i,s)
print(L[i],L[s])
热心网友 时间:2023-10-12 21:29
for x in a:
for y in a:
if(x + y == 22):
print('%d + %d = 22'% (x, y))