def c(n,m,out): if(m==0): return 1 x=n while x>=m: out.append(x) if(c(x-1,m-1,out)): print out out.pop() x-=1 return 0 c(10,8,out=[])
def permutation(listobj, length): assert listobj != None and 0 < length <= len(listobj) if(length == 1): return [ [x] for x in listobj ] result = [] for i in range(len(listobj)): cp = list(listobj) cur = cp[i] del cp[i] result.extend( [cur] x for x in permutation(cp, length-1) ) return result
n个取m个数的组合数问题