题目描述
给定数字n,n的半数序列集是(1)在 n 的右边加上一个自然数,但该自然数不能超过最近添加的数的一半,这样生了新的序列;(2)按此规则进行处理,直到不能再添加自然数为止。例如,4的半数序列集是{4,4 2,4 2 1,4 1}。
输入
一个整数 n,(0<n<=50)。
输出
按照数字降序,输出集合所有序列,每个序列一行,每个数字后面跟一个空格。
样例输入
6
样例输出
6 3 1 6 3 6 2 1 6 2 6 1
代码实现
import java
.util
.Scanner
;
public class Main {
int n
;
int[] A
;
public Main() {
Scanner s
=new Scanner(System
.in
);
n
=s
.nextInt();
A
=new int[n
]; A
[0]=n
;
Search(1);
}
void Search(int pos
) {
for(int i
=A
[pos
-1]/2;i
>=1;i
--) {
A
[pos
]=i
;
Search(pos
+1);
}
for(int k
=0;k
<pos
;k
++) System
.out
.print(A
[k
]+" ");
System
.out
.println();
}
public static void main(String
[] args
) {
Main h
=new Main();
}
}