python计算组合数和阶乘
来源:http://wiki.jxqc.org/mediawiki/index.php?title=Python%E8%AE%A1%E7%AE%97%E7%BB%84%E5%90%88%E6%95%B0
python计算组合数的方法很简单,如下函数即可实现:
import operatordef c(n,k): return reduce(operator.mul, range(n - k + 1, n + 1)) /reduce(operator.mul, range(1, k +1))def fac(n): return reduce(operator.mul, range(1,n+1))print c(10,2)print fac(5)