40#include <gtest/gtest.h>
49 const size_t n =
vals.size();
55 for (
size_t i = 0; i < n; ++i)
68 for (
size_t idx : selected)
184 for (
size_t k = 0;
k <
r.selected_indices.size(); ++
k)
200 for (
int i = 1; i <= 20; ++i)
212 for (
size_t k = 0;
k < r2.selected_indices.size(); ++
k)
234 for (
int target = 0; target <= 30; ++target)
245 std::mt19937
rng(4242);
248 const size_t n = 1 +
rng() % 18;
251 for (
size_t i = 0; i < n; ++i)
252 vals.append(
static_cast<int>(
rng() % 11));
254 const int target =
static_cast<int>(
rng() % 45);
272 std::mt19937
rng(2024);
275 const size_t n = 1 +
rng() % 22;
278 for (
size_t i = 0; i < n; ++i)
279 vals.append(
static_cast<int>(
rng() % 41) - 20);
281 const int target =
static_cast<int>(
rng() % 61) - 30;
294 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.
size_t blossom_maximum_cardinality_matching(const GT &g, DynDlist< typename GT::Arc * > &matching, SA sa=SA())
Alias of compute_maximum_cardinality_general_matching().
Main namespace for Aleph-w library functions.
bool subset_sum_exists(const Array< T > &values, T target)
Check if a subset summing to target exists (space-optimized).
size_t subset_sum_count(const Array< T > &values, T target)
Count the number of subsets that sum to target.
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)
Solve the subset sum problem via meet-in-the-middle (MITM).
Subset_Sum_Result< T > subset_sum(const Array< T > &values, T target)
Solve the subset sum problem 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.