Fast computation of multi-category number of combinations [closed]

给你一囗甜甜゛ 提交于 2019-11-28 02:21:36

问题


I have to evaluate the following formula for permutations with repeated objects

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

wheren <= 500 and 1 <= ri <= 10 (there are n objects in total out of which r1 are alike of 1 kind , r2 are alike of 2nd kind and so on and the formula indicates the number of permutations of such objects).

I need an efficient coding solution for this because working with big integers in Java doesn't prove to be fruitful for large cases.

Thanks in advance.


回答1:


You can do this in java by using

public class Permutation

designed to achieve a kind of your problem.

See this link for your reference

OR

like this :

private static Double calculatePermutationEntropy(List<Double> 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<String> result = new ArrayList<String>();
 // iterate over the input
 for (int i = 0; i < valuesSize - baseOrder + 1; i++) {
   List<Double> neightbors = values.subList(i, i + baseOrder);

   List<Double> orderedValues = new ArrayList<Double>(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);
}

source



来源:https://stackoverflow.com/questions/9107653/fast-computation-of-multi-category-number-of-combinations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!