50 for (
size_t i = 0; i < s.size(); ++i)
61 std::cout <<
"------------------------------------------------------------\n";
66 std::cout <<
"[1] next_permutation with duplicates (multiset)\n";
72 std::cout << std::setw(3) <<
count <<
" : ";
79 std::cout << std::setw(3) <<
count <<
" : ";
84 std::cout <<
"Total distinct lexicographic permutations: " <<
count <<
"\n";
85 std::cout <<
"After last step, reset to first: ";
92 std::cout <<
"[2] next_permutation with custom comparator (descending order)\n";
99 std::cout <<
"Step " <<
step <<
" -> ";
110 std::cout <<
"[3] next_combination_indices (k-combinations over [0..n))\n";
120 std::cout << std::setw(3) <<
count <<
" : ";
128 std::cout <<
"Total combinations C(" << n <<
", 3): " <<
count
129 <<
" (verified by combination_count = "
135 std::cout <<
"[4] next_combination_mask (fixed-popcount bitmask)\n";
145 std::cout << std::setw(3) <<
count <<
" : mask = ";
146 for (
size_t b = n; b > 0; --b)
147 std::cout << (((mask >> (b - 1)) & 1ULL) ?
'1' :
'0');
154 std::cout <<
"Total bitmask combinations: " <<
count <<
"\n\n";
159 std::cout <<
"[5] for_each_combination / build_combinations\n";
163 "geom",
"strings",
"graphs",
"dp",
"net"
166 std::cout <<
"Feature triplets:\n";
177 std::cout <<
"\nMaterialized pairs: " << pairs.size() <<
"\n";
178 std::cout <<
"First: ";
180 std::cout <<
" | Last: ";
188 std::cout <<
"\n=== Combinatorics / Enumeration ===\n\n";
196 std::cout <<
"Done.\n";
Combinatorics utilities: permutations, combinations and matrix transposition.
Simple dynamic array with automatic resizing and functional operations.
Main namespace for Aleph-w library functions.
bool for_each_combination(const Array< T > &values, const size_t k, Op &&op)
Enumerate all k-combinations of an Array<T> in lexicographic index order.
Array< Array< T > > build_combinations(const Array< T > &values, const size_t k)
Materialize all k-combinations of Array<T>.
bool next_combination_indices(Array< size_t > &idx, const size_t n, const bool reset_on_last=true)
Advance an index-combination [i0 < i1 < ... < i(k-1)] to the next one.
bool next_combination_mask(uint64_t &mask, const size_t n, const bool reset_on_last=true)
Advance a fixed-popcount bitmask to the next combination (Gosper hack).
Divide_Conquer_DP_Result< Cost > divide_and_conquer_partition_dp(const size_t groups, const size_t n, Transition_Cost_Fn transition_cost, const Cost inf=dp_optimization_detail::default_inf< Cost >())
Optimize partition DP using divide-and-conquer optimization.
bool next_permutation(Array< T > &a, Compare cmp=Compare(), const bool reset_on_last=true)
Compute the next lexicographic permutation of an Array.
uint64_t first_combination_mask(const size_t k)
Build the first k-of-64 combination mask (k low bits set).
size_t combination_count(size_t n, size_t k)
Compute n choose k with overflow checks.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
void print_seq(const C< T > &c)