c++ - 一个算法:在极大的无序序列中寻找三个数和大于等于N的所有组合数量
PHP中文网
PHP中文网 2017-04-17 11:21:56
0
2
600

比如: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中文网

认证高级PHP讲师

reply all(2)
巴扎黑

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

Ty80

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

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!