【发布时间】:2015-12-06 02:49:35
【问题描述】:
所以我有一个双打数组。我想在这个大小为 k 的数组中找到一个子集,并将所有不在子集中的子集存储到不同的子数组中。我想对所有可能的子集执行此操作,而无需重复。
最好的方法是什么?
double[] sample = {
1.0, 3.0, 1.6, 2.1, 2.5, 2.7, 2.3, 1.5, 1.1, 0.5, 2.0, 2.0, 1.2, 1.2, 1.3, 0.5, 1.4, 2.4
};
public static void main(String[] args) {
ArrayList < double[] > list = new ArrayList < double[] > ();
double[] noo = pickNRandom(sample);
if (!list.contains(noob)) { //here I want to make sure that it is a unique subset
list.add(noob);
for (double a: noob) {
System.out.print(a + " ");
}
System.out.println("");
}
}
public static double[] pickNRandom(double[] lst) { //finding a random subset
double[] i = lst;
Collections.shuffle(Arrays.asList(i));
double[] fin = {
i[0], i[1], i[2], i[3], i[4], i[5], i[6], i[7]
};
return fin;
}
【问题讨论】:
-
到目前为止你尝试过什么方法?
-
这是一个很好的起点:stackoverflow.com/questions/4640034/…
标签: java permutation