V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
meteor2013
V2EX  ›  程序员

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

  •  
  •   meteor2013 · 2015-03-03 00:37:36 +08:00 · 2086 次点击
    这是一个创建于 3336 天前的主题,其中的信息可能已经有所发展或是发生改变。
    比如有一个list(A,B , C ,D , E)

    选出

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

    如果嵌套的话,应该是 O=n^2
    有没好得办法呢?
    7 条回复    2015-03-03 10:33:36 +08:00
    66450146
        1
    66450146  
       2015-03-03 00:41:00 +08:00
    总的数量就是 O(n^2) 啊,肯定不能再减了……
    wecan
        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
        3
    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
        4
    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
        5
    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
        6
    yegle  
       2015-03-03 08:18:52 +08:00
    强烈怀疑楼主在优化一些可能并不热的代码…
    wecan
        7
    wecan  
       2015-03-03 10:33:36 +08:00 via Android
    @billwsy 不好意思昨天刚装的系统没中文输入法
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1224 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 17:57 · PVG 01:57 · LAX 10:57 · JFK 13:57
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.