algorithm - 查找单词组合的最佳算法?

标签 algorithm

<分区>

Possible Duplicate:
How to find all possible subsets of a given array?

假设你有

一个

你可以有a,b,ab

最好的方法是什么?

最佳答案

来自itertools recipes :

def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))

这是一个标准的 python 模块,因此阅读它应该会让您深入了解它是如何实现的以及使用了什么算法。我不知道它是否是最好的,但它是来自现实世界的算法。

关于algorithm - 查找单词组合的最佳算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2958753/

相关文章:

algorithm - bool 可满足性的类调度 [多项式时间缩减] 第 2 部分

algorithm - matlab代码优化——聚类算法KFCG

c - Cormen 的 HeapSort 算法在 C 中的实现

algorithm - 将平衡树映射到平面上的点

algorithm - 有没有好的开源或者免费的中文分词算法?

java - 我无法在合并排序中使用 java 获得反转次数

c# - 如何在 C# 中以编程方式创建柔和的颜色?

c++ - 计算定点数的 sin() 和 cos() 的简单三角算法

algorithm - 寻找一个简单的哈希表实现示例作为引用

algorithm - 为什么这个指数在这个例子中以这种方式计算?