快速计算多类别组合数

我必须为重复对象的排列评估以下公式

n!/(r1! * r2! * r3! * ......... * rn!)

其中n <= 5001 <= ri <= 10 (总共有n个对象,其中r1与1种类似,r2与第2种类似,依此类推,公式表示此类对象的排列数)。

我需要一个有效的编码解决方案,因为在Java中使用大整数并不能certificate对于大型案例来说是富有成效的。

提前致谢。

您可以使用java在java中执行此操作

 public class Permutation 

旨在实现一种你的问题。

请参阅此链接以供参考

要么

像这样 :

 private static Double calculatePermutationEntropy(List values, int baseOrder) { int valuesSize = values.size(); if (baseOrder >= valuesSize + 1) { throw new RuntimeException("The size of the values is bigger than the order"); } List result = new ArrayList(); // iterate over the input for (int i = 0; i < valuesSize - baseOrder + 1; i++) { List neightbors = values.subList(i, i + baseOrder); List orderedValues = new ArrayList(neightbors); String window = ""; for (int j = 0; j < neightbors.size(); j++) { // add the indexes in a string representation window += orderedValues.indexOf(neightbors.get(j)); } result.add(window); } // use the shannon entropy calculation to get the result return calculateShannonEntropy(result); } 

资源