9-p09_comb组合数


def comb(m,n):
    if n==0 or m==n :
        return 1
    return comb(m-1,n-1) + comb(m-1,n)


if __name__ == '__main__':#先写主程序,再写子程序的子程序
    for m in range(1,10+1):
        for n in range(0,m+1):
            print('C(%d,%d)=%d' % (m,n,comb(m,n)))

D:\Anaconda\python.exe D:/AI20/06_codes/deeplearning_20/p09_comb.py
C(1,0)=1
C(1,1)=1
C(2,0)=1
C(2,1)=2
C(2,2)=1
C(3,0)=1
C(3,1)=3
C(3,2)=3
C(3,3)=1
C(4,0)=1
C(4,1)=4
C(4,2)=6
C(4,3)=4
C(4,4)=1
C(5,0)=1
C(5,1)=5
C(5,2)=10
C(5,3)=10
C(5,4)=5
C(5,5)=1
C(6,0)=1
C(6,1)=6
C(6,2)=15
C(6,3)=20
C(6,4)=15
C(6,5)=6
C(6,6)=1
C(7,0)=1
C(7,1)=7
C(7,2)=21
C(7,3)=35
C(7,4)=35
C(7,5)=21
C(7,6)=7
C(7,7)=1
C(8,0)=1
C(8,1)=8
C(8,2)=28
C(8,3)=56
C(8,4)=70
C(8,5)=56
C(8,6)=28
C(8,7)=8
C(8,8)=1
C(9,0)=1
C(9,1)=9
C(9,2)=36
C(9,3)=84
C(9,4)=126
C(9,5)=126
C(9,6)=84
C(9,7)=36
C(9,8)=9
C(9,9)=1
C(10,0)=1
C(10,1)=10
C(10,2)=45
C(10,3)=120
C(10,4)=210
C(10,5)=252
C(10,6)=210
C(10,7)=120
C(10,8)=45
C(10,9)=10
C(10,10)=1

Process finished with exit code 0

发布了88 篇原创文章 · 获赞 2 · 访问量 1310

猜你喜欢

转载自blog.csdn.net/HJZ11/article/details/104460009
今日推荐