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
It can be done with recursion. You don't say if you just want the number of possibilities or the actual possibilities.
One thing you want to do is avoid repetition meaning don't count 4 and 3 also as 3 and 4. One way to do that is to create sequences of non-descending group sizes.
Probably the best data structure for this is a tree:
root
+- 12
+- 9
| +- 3
+- 8
| +- 4
+- 7
| +- 5
+- 6
| +- 6
| +- 3
| +- 3
+- 5
| +- 4
| +- 3
+- 4
| +- 4
| +- 4
+- 3
+- 3
+- 3
+- 3
Then to find the number of combinations you simply count the leaf nodes. To find the actual combinations you just walk the tree.
The algorithm for building such a tree goes something like this:
i
from size
down to minSize
;i
;j
from minSize
to i
that is less than or equal to i
j
or something very close to that.