1,000,000 , 3 , 166 666 166 667 000 000 . , , , .
, . "GENERATING ALL COMBINATIONS" .
,
, :
>>> import itertools
>>> import pprint
>>> A = [1, 2, 3, 4, 100]
>>> combinations = sorted(itertools.combinations(A, 3), key=sum)
>>> pprint.pprint(combinations)
[(1, 2, 3),
(1, 2, 4),
(1, 3, 4),
(2, 3, 4),
(1, 2, 100),
(1, 3, 100),
(1, 4, 100),
(2, 3, 100),
(2, 4, 100),
(3, 4, 100)]
sum() key-function ().
nCr , , , A , , .