怎样选出不同的两两组合效率比较高呢?

2015-03-03 00:37:36 +08:00
 meteor2013
比如有一个list(A,B , C ,D , E)

选出

AB, AC, AD,AE, BC, BD, BD, CD,CE, DE

如果嵌套的话,应该是 O=n^2
有没好得办法呢?
2091 次点击
所在节点    程序员
7 条回复
66450146
2015-03-03 00:41:00 +08:00
总的数量就是 O(n^2) 啊,肯定不能再减了……
wecan
2015-03-03 01:11:04 +08:00
I would say there can be no improvements if you do not provide any further prior information. From what you've provided, it seems your problem is enumeration-based, which suggests you have to thoroughly check each and every possible solution for its quality measure.

You may be able to improve if you look into your problem and look for possible priors such as p(AB)=p(B|A)p(A). In this case, for example, you can use dynamic programming to save yourself the time to calculate p(A) for multiple times.

Hope this helps.
bugcoder
2015-03-03 01:14:04 +08:00
http://stackoverflow.com/questions/5360220/how-to-split-a-list-into-pairs-in-all-possible-ways
看这个地方,不过真心没看懂那个最优的gatoatigrado的算法, 求高手解释。
wecan
2015-03-03 01:32:04 +08:00
@bugcoder Forgive me if I'm wrong but I don't think it's the same question OP asked. The problem on stackoverflow is to split a list into pairs, where each result is a list (which has been split into pairs). Whereas the OP's problem is to get all possible pairs where each result is just one pair.

Anyways I may have misunderstood OP's problem in my last reply if the problem is purely on the splitting process...
billwsy
2015-03-03 06:45:34 +08:00
@wecan Apparently you have given informative, useful and helpful information. However I am quite curious if there is any specific reason that you reply in English, given you have a lot of posts in Chinese before.
yegle
2015-03-03 08:18:52 +08:00
强烈怀疑楼主在优化一些可能并不热的代码…
wecan
2015-03-03 10:33:36 +08:00
@billwsy 不好意思昨天刚装的系统没中文输入法

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/174061

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX