public class Arrangement extends Object implements Serializable
| Constructor and Description |
|---|
Arrangement(String[] datas)
构造
|
| Modifier and Type | Method and Description |
|---|---|
static long |
count(int n)
计算排列数,即A(n, n) = n!
|
static long |
count(int n,
int m)
计算排列数,即A(n, m) = n!
|
static long |
countAll(int n)
计算排列总数,即A(n, 1) + A(n, 2) + A(n, 3)...
|
Iterable<String[]> |
iterate(int m)
返回一个排列的迭代器
|
List<String[]> |
select()
全排列选择(列表全部参与排列)
|
List<String[]> |
select(int m)
从当前数据中选择 m 个元素,生成所有「不重复」的排列(Permutation)。
|
List<String[]> |
selectAll()
生成当前数据的全部不重复排列(长度为 1 至 n 的所有排列)。
|
public Arrangement(String[] datas)
datas - 用于排列的数据public static long count(int n)
n - 总数public static long count(int n,
int m)
n - 总数m - 选择的个数public static long countAll(int n)
n - 总数public List<String[]> select(int m)
说明:
A(n, m) = n! / (n - m)!举例:
datas = ["1","2","3"] m = 2 输出: ["1","2"] ["1","3"] ["2","1"] ["2","3"] ["3","1"] ["3","2"] 共 6 个(A(3,2)=6)
m - 选择的元素个数public List<String[]> selectAll()
说明:
m=1: ["1"], ["2"], ["3"] → 3 个 m=2: ["1","2"], ["1","3"], ["2","1"], ... → 6 个 m=3: ["1","2","3"], ["1","3","2"], ["2","1","3"], ...→ 6 个 总共:3 + 6 + 6 = 15
Copyright © 2025. All rights reserved.