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

被折叠的 条评论
为什么被折叠?



