41# include <gtest/gtest.h>
51 const size_t n =
vals.size();
57 for (
size_t i = 0; i < n; ++i)
72 for (
size_t idx : selected)
190 for (
size_t k = 0;
k <
r.selected_indices.size(); ++
k)
206 for (
int i = 1; i <= 20; ++i)
218 for (
size_t k = 0;
k < r2.selected_indices.size(); ++
k)
240 for (
int target = 0; target <= 30; ++target)
246 <<
"Disagreement at target=" << target;
252 std::mt19937
rng(4242);
255 const size_t n = 1 +
rng() % 18;
258 for (
size_t i = 0; i < n; ++i)
259 vals.append(
static_cast<int>(
rng() % 11));
261 const int target =
static_cast<int>(
rng() % 45);
279 std::mt19937
rng(2024);
282 const size_t n = 1 +
rng() % 22;
285 for (
size_t i = 0; i < n; ++i)
286 vals.append(
static_cast<int>(
rng() % 41) - 20);
288 const int target =
static_cast<int>(
rng() % 61) - 30;
301 for (
int i = 0; i < 128; ++i)
Subset sum algorithms: classical DP and meet-in-the-middle.
Space-efficient bit array implementation.
Simple dynamic array with automatic resizing and functional operations.
T & append(const T &data)
Append a copy of data
void reserve(size_t cap)
Reserves cap cells into the array.
Contiguous array of bits.
Main namespace for Aleph-w library functions.
bool subset_sum_exists(const Array< T > &values, T target)
Subset sum existence check (space-optimized).
size_t subset_sum_count(const Array< T > &values, T target)
Count the number of subsets summing to target.
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 exists(Container &container, Operation &operation)
Return true if at least one element satisfies a predicate.
Subset_Sum_Result< T > subset_sum_mitm(const Array< T > &values, T target)
Subset sum via meet-in-the-middle (MITM).
Subset_Sum_Result< T > subset_sum(const Array< T > &values, T target)
Subset sum via classical DP with reconstruction.
Itor::difference_type count(const Itor &beg, const Itor &end, const T &value)
Count elements equal to a value.
T sum(const Container &container, const T &init=T{})
Compute sum of all elements.