Algorithm to determine possible groups of items

后端 未结 6 1734
遥遥无期
遥遥无期 2021-02-03 11:51

I am scratching my head trying to do this and it\'s eating me up. I know it is not THAT complex. I have a number of items, this number can be equal or greater than three. Then I

6条回答
  •  孤街浪徒
    2021-02-03 12:35

    What you are describing is a less general version of the partition function.

    The algorithms already given are ridiculously complicated, here is a simpler one (in pseudo-code, I will leave it up to you to translate to Java :) )

    p(min, n):
        if min > n: return 0
        if min = n: return 1
        return p(min+1, n) + p(min, n-min)
    

提交回复
热议问题