我怎样才能最大限度地划分一组? [英] How can I maximally partition a set?
问题描述
我试图解决的项目欧拉问题之一。因此,我需要一种算法,这将有助于我找到了一套所有可能的分区,以任意顺序。
I'm trying to solve one of the Project Euler problems. As a consequence, I need an algorithm that will help me find all possible partitions of a set, in any order.
例如,给定一组 2 3 3 5
:
2 | 3 3 5
2 | 3 | 3 5
2 | 3 3 | 5
2 | 3 | 3 | 5
2 5 | 3 3
等。 pretty的该组的成员的多每个可能的组合。我搜索了网络课程的,但还没有找到太多这是直接对我很有用,因为我讲的程序员-ESE不先进,数学东南偏东。
and so on. Pretty much every possible combination of the members of the set. I've searched the net of course, but haven't found much that's directly useful to me, since I speak programmer-ese not advanced-math-ese.
谁能帮我这个?我可以读pretty的多任何编程语言,从基础到Haskell的,所以在发布任何一种语言,你的愿望。
Can anyone help me out with this? I can read pretty much any programming language, from BASIC to Haskell, so post in whatever language you wish.
推荐答案
你有没有考虑一个搜索树?每个节点将重新present的在那里把元素的选择和叶子节点都是答案。我不会给你code,因为这是项目欧拉乐趣的一部分;)
Have you considered a search tree? Each node would represent a choice of where to put an element and the leaf nodes are answers. I won't give you code because that's part of the fun of Project Euler ;)
这篇关于我怎样才能最大限度地划分一组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!