使用循环;
阶乘的实现:
def fac(n): r = 1. for i in range(1, n+1): r *= i return r
排列:
Anm=m!n!=(m−n+1)⋯m
def perm(m, n):
r = 1.
for i in range(n):
r *= m-i
return r
组合:
(mn)=m!n!(m−n)!=Anmn! def comb(m, n): return perm(m, n)/float(fac(n))