File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1- class Permutation implements java .util .Iterator <int []> {
1+ /*
2+ * Verified
3+ * https://atcoder.jp/contests/abc054/submissions/16977824
4+ */
5+ class Permutation implements java .util .Iterator <int []>, Iterable <int []> {
26 private int [] next ;
37
48 public Permutation (int n ) {
@@ -17,6 +21,11 @@ public int[] next() {
1721 return r ;
1822 }
1923
24+ @ Override
25+ public java .util .Iterator <int []> iterator () {
26+ return this ;
27+ }
28+
2029 public static int [] nextPermutation (int [] a ) {
2130 if (a == null || a .length < 2 )
2231 return null ;
Original file line number Diff line number Diff line change 44
55$N$が与えられたとき,長さ$N$の順列を辞書順に列挙することができます.
66
7+ また,拡張 for 文によるイテレーションをサポートしています.
8+ 以下のイテレーションは,時間計算量 $O(N * N!)$で動作します.
9+
10+ ```
11+ Permutation perm = new Permutation(n);
12+ for (int[] p : perm) {
13+ // code here
14+ }
15+ ```
16+
717## コンストラクタ
818
919### Permutation
@@ -32,6 +42,14 @@ public int[] next()
3242
3343イテレータの後続の要素を取得します.計算量 $O(N)$
3444
45+ ### iterator
46+
47+ ``` java
48+ public Iterator<int[]> iterator()
49+ ```
50+
51+ 順列を列挙するイテレータを取得します.
52+
3553### nextPermutation
3654
3755``` java
You can’t perform that action at this time.
0 commit comments