permutohedronを使う
順列全探索(昇順)
code:Rust
while {
do_something(&xs);
xs.next_permutation()
} {}
ちなみにwhile {} {}というのは条件式の部分にすべての式を詰め込むことで擬似的なdo-whileを実現するテク
順列全探索(降順)
code:Rust
xs.sort();
while {
do_something(&xs);
xs.prev_permutation()
} {}
組合せ全探索($ _n \mathrm C _r)
code:Rust
while {
do_something(&flags);
flags.next_permutation()
} {}
重複組合せ全探索($ _n \mathrm{H} _r)
code:Rust
// flags: true を仕切りとして、 false をランレングス圧縮すると各種類ごとの使う個数になる
while {
do_something(&flags);
flags.next_permutation()
} {}