The Algorithm on Combinations

本文介绍了几种计算组合数的方法,包括递归算法、利用组合数性质的计算方式以及使用阶乘直接计算。并通过示例代码展示了这些方法的具体实现。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

In combinatorial mathematics, a combination is an un-ordered collection of distinct elements, usually of a prescribed size and taken from a given set. (An ordered collection of distinct elements would sometimes be called a permutation, but that term is ambiguous; it can also mean "reordering of all terms", among other related notions.) Given such a set S, a combination of elements of S is just a subset of S, where, as always for (sub)sets the order of the elements is not taken into account (two lists with the same elements in different orders are considered to be the same combination). Also, as always for (sub)sets, no elements can be repeated more than once in a combination; this is often referred to as a "collection without repetition". For instance, {1,1,2} is not a combination of three digits; as a set this is the same as {1,2,1} or {2,1,1} or even {1,2}. (From WiKi) 

 



Some "recursive algorithm" ways to calculate the combination.

 

[1] The process of this algorithm could be illustrated as Fig.1 as below.

 递归求解组合数



[2] Another way makes use of the equation "C(n,m)=C(n-1,m-1)+C(n-1,m)" .

  

[3] From the definition of combination, since as we all know, C(n,m) is equvivalent to n!/(m!*(n-m)!).

  

As the ways mentioned above, you may easily find that these ways just only can be used for solving the little number, like C(4,2). But if need to solve C(100000,2), even more C(100000,200), these ways cannot work! 

In the beginning, the solution I thought is to reduce a fraction to make the result little, the ways like following:

  

In fact, this ways  can reduce the results in some extents(the loss of accuracy), if for C(100000,200), it still connot work!


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值