由网友(轰炸男厕所)分享简介:我试图找到一个很好的递归算法,打印出一系列的子集。例如I'm trying to find a good recursive algorithm to print out the subsets of a set.For example5号:给出集合{1,2,3,4,5}和关闭长度为3的子集给出了这样的输出:...
我试图找到一个很好的递归算法,打印出一系列的子集。 例如
I'm trying to find a good recursive algorithm to print out the subsets of a set. For example
5号:给出集合{1,2,3,4,5}和关闭长度为3的子集给出了这样的输出:
{5,4,3}
{5,4,2}
{5,4,1}
{5,3,2}
{5,3,1}
{5,2,1}
{4,3,2}
{4,3,1}
{4,2,1}
{3,2,1}
我试过很多东西,但它不工作。在互联网上所有的例子都是用套算法,但我想我自己写的,学习的目的。
I've tried many things but it doesn't work. On the internet all the examples are with sets algorithms but I want to write my own, for learning purposes.
可能有人帮助我?
亲切的问候,
推荐答案
最后,它的工作原理:
public static void Dvz(String s, int x, int y){
int i;
if(y > 0)
for(i = x; i >= y; i--)
Dvz(s+i, i-1, y-1);
else
System.out.println(s);
}
相关推荐
最新文章