组合的多品类数量的快速计算 [英] Fast computation of multi-category number of combinations

查看:159
本文介绍了组合的多品类数量的快速计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有重复的对象,以评估排列如下公式

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

N!/(R1!* R2!* R3!* ......... * RN!)

其中, N'LT = 500 1< = RI< = 10 (有n个对象在总外面R1是相似1种,R2是完全相同的第2种的等和式表示这种对象的排列)的数量。

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).

我需要这样的一个有效的编码解决方案,因为在Java大整数工作并不能证明是卓有成效的大箱子。

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

先谢谢了。

推荐答案

您可以通过使用做到这一点在Java

You can do this in java by using

public class Permutation

设计,实现了一种你的问题。

designed to achieve a kind of your problem.

请参阅此链接为您参考

是这样的:

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);
}

这篇关于组合的多品类数量的快速计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆