I ran into this particular problem at work and found it quite interesting. While implementing a multi-level image threshholding algorithm, I discovered that I needed to find all the ways I could partition a range of integers into some number of consecutive groups. I like my solution, but there may be better approaches. Here is the problem: given some set S of consecutive integers, find all possible partitions of S into M disjoint subsets of consecutive integers such that S is covered its subsets
for example:
if N=7, M=4, and S=[0,1,2,3,4,5,6], all the valid partition sets are:
[[0], [1, 2, 3], [4], [5, 6]]
[[0, 1, 2, 3], [4], [5], [6]]
[[0, 1], [2], [3, 4, 5], [6]]
[[0, 1], [2, 3], [4, 5], [6]]
[[0, 1, 2], [3], [4], [5, 6]]
[[0], [1], [2], [3, 4, 5, 6]]
[[0, 1], [2, 3, 4], [5], [6]]
[[0, 1], [2, 3], [4], [5, 6]]
[[0, 1, 2], [3], [4, 5], [6]]
[[0], [1, 2, 3, 4], [5], [6]]
[[0], [1], [2, 3, 4, 5], [6]]
[[0], [1, 2, 3], [4, 5], [6]]
[[0], [1], [2, 3], [4, 5, 6]]
[[0, 1], [2], [3], [4, 5, 6]]
[[0, 1, 2], [3, 4], [5], [6]]
[[0], [1, 2], [3, 4, 5], [6]]
[[0], [1, 2], [3, 4], [5, 6]]
[[0], [1], [2, 3, 4], [5, 6]]
[[0], [1, 2], [3], [4, 5, 6]]
[[0, 1], [2], [3, 4], [5, 6]]
Good luck!