This seems like a simple request, but google is not my friend because "partition" scores a bunch of hits in database and filesystem space.
I need to enumerate all partitions of an array of N values (N is constant) into k sub-arrays. The sub-arrays are just that - a starting index and ending index. The overall order of the original array will be preserved.
For example, with N=4 and k=2:
[ | a b c d ] (0, 4)
[ a | b c d ] (1, 3)
[ a b | c d ] (2, 2)
[ a b c | d ] (3, 1)
[ a b c d | ] (4, 0)
And with k=3:
[ | | a b c d ] (0, 0, 4)
[ | a | b c d ] (0, 1, 3)
:
[ a | b | c d ] (1, 1, 2)
[ a | b c | d ] (1, 2, 1)
:
[ a b c d | | ] (4, 0, 0)
I'm pretty sure this isn't an original problem (and no, it's not homework), but I'd like to do it for every k <= N, and it'd be great if the later passes (as k grows) took advantage of earlier results.
If you've got a link, please share.