Sum-of-Product of subsets
问题 Is there a name for this operation? And: is there a closed-form expression? For a given set of n elements, and value k between 1 and n, Take all subsets (combinations) of k items Find the product of each subset Find the sum of all those products I can express this in Python, and do the calculation pretty easily: from operator import mul from itertools import combinations from functools import reduce def sum_of_product_of_subsets(list1, k): val = 0 for subset in combinations(list1, k): val +=