How can I obtain all combinations for a list where combination size need only be static eg. if the list has 4 elements then it will only need permutations of length 4 not 3, 2 and 1. I'm guessing this will need recursion. Unique combinations would be helpful but I'd like开发者_开发知识库 to see it in simplest (no uniqueness?) form for my puppy power.
set s = { x1, x2, x3, x4 };
array solution;
permute( i ) =>
if( i == 0 ) => print and return;
while unused elements in set =>
take element from set which is not in solution;
put element in solution;
permute( i - 1 );
remove element from solution;
If you want a more specific answer you have to create a more specific question. Show some code/effort/whatever..
精彩评论