coded by 老鱼

from itertools import combinations, product

def func(numbers, m, s):
    def determinate(args):
        return sum(args) == s
    return filter(determinate, product(numbers, repeat = m))

print(func(range(10), 2, 5))

输出:
    [(0, 5), (1, 4), (2, 3), (3, 2), (4, 1), (5, 0)]


【 在 wenti (question) 的大作中提到: 】
: n个数,任取m个,使得和为s
: m不定,可重复取

posted on 2012-09-18 10:37  fenix  阅读(107)  评论(0编辑  收藏  举报