这里使用python来求一个组合数
def combine(l_date, n, m, l_output, result):
for i in range(n, m - 1, -1):
l_output[m - 1] = l_date[i - 1]
if m > 1:
combine(l_date, i - 1, m - 1, l_output, result)
else:
print l_output
result.append(l_output)
result = []
l_output = [0]*2
list_date = [0, 1, 2]
combine(list_date, 3, 2, l_output, result)
print result
输出结果,与加入list的数据不一样
[1, 2]
[0, 2]
[0, 1]
[[0, 1], [0, 1], [0, 1]]
将程序改成这样
def combine(l_date, n, m, l_output, result):
for i in range(n, m - 1, -1):
l_output[m - 1] = l_date[i - 1]
if m > 1:
combine(l_date, i - 1, m - 1, l_output, result)
else:
print l_output
res = l_output[:]
result.appe