其他分享
首页 > 其他分享> > combination

combination

作者:互联网

C52 5*4/2*1

(m!)/(n!*(m-n)!)
=(m*(m-1)*(m-2)*…*(m-n+2)*(m-n+1))/(n!)
= ((m-n+1)/1)*((m-n+2)/2)*((m-n+3)/3)*…*((m-n+n)/n)
= ∏((m-n+k)/k)【k=1,2,3,…,n】



func cn(n, k u) u {
if k > (n>>1) {
k = n - k
}
numerator := u(1)
umax := u(0)
umax -= 1
for i := u(1); i <= k; i++ {
//(a, 0) (b, r)
if numerator > umax / n {
panic(i)
}
numerator *= n
n--
numerator /= i //denominator
}
return numerator
}

标签:return,C52,combination,--,numerator,umax
来源: https://www.cnblogs.com/Janly/p/16362583.html