动态大小集的静态大小排列 [英] Static sized permutations from Dynamic sized set
本文介绍了动态大小集的静态大小排列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取列表的所有组合,其中组合大小仅需为静态,例如如果列表包含4个元素,则仅需要长度4的排列,而不是3、2和1。我猜测这将需要递归。独特的组合会有所帮助,但我希望以最简单的形式(没有唯一性?)来查看我的小狗威力。
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..
这篇关于动态大小集的静态大小排列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文