【问题标题】:How to generate combination of vectors [duplicate]如何生成向量的组合[重复]
【发布时间】:2011-03-08 04:38:24
【问题描述】:

可能重复:
combination and permutation in C++

我有一个大小为“n”的向量。例如,一个 n=4 的向量,<1,2,3,4>。如何生成此向量的所有 n-1 组合。在此示例中,4 chose 3。我希望输出为<1,2,3> <1,2,4> <1,3,4> <2,3,4>。谢谢。

【问题讨论】:

  • combination and permutation in C++ 的副本,尤其是 Charles Bailey 的绝妙解决方案。
  • n-1 的元素组合与n-combinations 一样多。只有剩余的元素不存在。请记住这一点。
  • 感谢您的链接。我也投票决定关闭。

标签: c++ vector combinations


【解决方案1】:

首先查找 STL 的 next_permutation 函数。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-25
    • 2014-09-29
    • 2018-12-16
    相关资源
    最近更新 更多