1. \ (full array C_ {m} ^ {n} \) of the realization
[Required] input m, n, indexes of all possible combinations of output
def cmn(m, n):
if n ==1:
return [[i] for i in range(1, m+1)]
elif m==n:
return [ list(range(1, m+1)) ]
else:
temp1 = cmn(m-1, n)
temp2 = [ i+[m] for i in cmn(m-1, n-1)]
return temp1 + temp2
if __name__ == '__main__':
print( cmn(4, 3) )
2. subset of the total
def subsets(aim):
if len(aim) == 1:
return [aim]
result = subsets(aim[1:])
return result + [[aim[0]] + s for s in result]