是否有任何库用于进行这些设置操作。特定尺寸的所有可能的唯一集合
我有一组(x,y)点。然后我需要创建一个Set(族)集。家族中的每个Set都应包含一定数量的元素。一组中元素的顺序无关紧要。所以[m,l,n]与[l,m,n]相同。
是否有任何库用于进行这些设置操作。特定尺寸的所有可能的唯一集合
我有一组(x,y)点。然后我需要创建一个Set(族)集。家族中的每个Set都应包含一定数量的元素。一组中元素的顺序无关紧要。所以[m,l,n]与[l,m,n]相同。
您要求的内容叫做combinations。番石榴有a method计算排列,这是相关的。但是,如果您只需要组合,那么不太知道的combinatoricslib看起来像The Right Thing。下面是该库的网站为例,使用String
S:
// Create the initial vector
ICombinatoricsVector<String> initialVector = Factory.createVector(
new String[] { "red", "black", "white", "green", "blue" });
// Create a simple combination generator to generate 3-combinations of the initial vector
Generator<String> gen = Factory.createSimpleCombinationGenerator(initialVector, 3);
// Print all possible combinations
for (ICombinatoricsVector<String> combination : gen) {
System.out.println(combination);
}
AFAICS你需要一个'Point'类,然后谁拥有'设置',让我们说,'Figure'和持有其他类的类'设置
首先生成所有组合需要指数级更多的内存。但是,如果您在生成时处理每个组合,您的固定内存使用量会很小。生成组合是一个循环和递归的问题。 – 2013-04-24 20:29:38