You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何获取由互不相交子列表构成的最大组合集合?

问题需求

给定多个Integer类型的List,需获取所有满足「内部子列表两两无交集」的最大组合集合,组合内子列表顺序无关。

示例测试代码

@Test
public void test() {
    List<Integer> list1 = Arrays.asList(1, 2);
    List<Integer> list2 = Arrays.asList(3, 4);
    List<Integer> list3 = Arrays.asList(5, 6, 7);
    List<Integer> list4 = Arrays.asList(2, 3);
    List<Integer> list5 = Arrays.asList(7);
    List<Integer> list6 = Arrays.asList(3);
}

结果存储结构

List<List<List<Integer>>> result = new ArrayList<>();

期望输出结果

[[1, 2],[3, 4],[5, 6, 7]]
[[1, 2],[3, 4],[7]]
[[1, 2],[3],[5, 6, 7]]
[[1, 2],[3],[7]]
[[2, 3],[5, 6, 7]]
[[2, 3],[7]]

内容的提问来源于stack exchange,提问作者leihh

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.31 08:56:08