Discuss / Python / 利用杨辉三角第m行第n个数为C(m-1,n-1)的性质生成

利用杨辉三角第m行第n个数为C(m-1,n-1)的性质生成

Topic source

Exmlyshy

#1 Created at ... [Delete] [Delete and Lock User]

-- coding:utf-8 --

def jc(n):#阶乘 if n==0: return 1 return njc(n-1) def permutations(m,n):#计算排列组合C(m,n) i,s=0,1 if n==0: return 1 while i<n: s=sm m=m-1 i=i+1 return s//jc(n) def triangles():#杨辉三角 length,i=1,0 L=[1] while 1: yield L length=length+1 L=list(range(length)) i=0 while i<length: L[i]=permutations(length-1,i) i=i+1 n = 0 for t in triangles(): print(t) n = n + 1 if n == 10: break


  • 1

Reply