What was wrong with the suggestions given when you asked this Nesting 2 and help with nesting? This problem is NP-complete, so you will probably not find a better solution than trying every possible combination. Is enumerating all combinations the part you're having trouble with?