私はこの機能を700の整数のように大量に使用したいが、その機能は実行に時間がかかる。誰かがパフォーマンスを向上させるアイディアを持っていますか?複合Javaの性能
public static Set<Set<Integer>> combinations(List<Integer> groupSize, int k) {
Set<Set<Integer>> allCombos = new HashSet<Set<Integer>>();
// base cases for recursion
if (k == 0) {
// There is only one combination of size 0, the empty team.
allCombos.add(new HashSet<Integer>());
return allCombos;
}
if (k > groupSize.size()) {
// There can be no teams with size larger than the group size,
// so return allCombos without putting any teams in it.
return allCombos;
}
// Create a copy of the group with one item removed.
List<Integer> groupWithoutX = new ArrayList<Integer> (groupSize);
Integer x = groupWithoutX.remove(groupWithoutX.size() - 1);
Set<Set<Integer>> combosWithoutX = combinations(groupWithoutX, k);
Set<Set<Integer>> combosWithX = combinations(groupWithoutX, k - 1);
for (Set<Integer> combo : combosWithX) {
combo.add(x);
}
allCombos.addAll(combosWithoutX);
allCombos.addAll(combosWithX);
return allCombos;
}
"n!"よりも速い時間にすべての組み合わせを取得することはできません –
ブレークポイントを設定してステップを破り、実行するには長すぎる? (ストップウォッチを使用して) –
私はJavaで簡単な解決策を見ていません(Scalaは多くを助けるでしょう)。興味深い記事があります:https://stackoverflow.com/questions/3515739/parallel-programming-with-recursive-functions – marco