search

Home  >  Q&A  >  body text

c++ - 一个算法:在极大的无序序列中寻找三个数和大于等于N的所有组合数量

比如:1 4 2 5 9 中寻找大于6的组合

1 2 4
1 2 5
1 2 9
1 4 5
1 4 9
2 4 5
2 4 9
4 5 9

一共8个组合。

如果是自然数序列,可以先排序再找到最小的满足组合,接下来只需要复杂度为n的算法就可以得到结果。但是如果序列的值是离散的,使时间复杂度尽可能小的算法应该怎么考虑呢?

备注:
数值大于10^16

PHP中文网PHP中文网2805 days ago634

reply all(2)I'll reply

  • 巴扎黑

    巴扎黑2017-04-17 11:23:56

    Are there any problems with using the algorithm you mentioned for energy addition and comparison?

    reply
    0
  • PHP中文网

    PHP中文网2017-04-17 11:23:56

    Can’t we sort natural numbers? If the value is larger, you can also sort it, and the complexity is only related to the number of numbers you have

    reply
    0
  • Cancelreply