TheAlgorithms/C++ 1.0.0
All the algorithms implemented in C++
|
Implementation of the Subset Sum problem. More...
#include <cassert>
#include <cstdint>
#include <iostream>
#include <vector>
Go to the source code of this file.
Namespaces | |
namespace | backtracking |
for vector container | |
namespace | Subsets |
Functions for the Subset Sum problem. | |
Functions | |
uint64_t | backtracking::subset_sum::number_of_subsets (int32_t sum, const std::vector< int32_t > &in_arr) |
The main function implements count of subsets. | |
static void | test () |
Test implementations. | |
int | main () |
Main function. | |
Implementation of the Subset Sum problem.
We are given an array and a sum value. The algorithm finds all the subsets of that array with sum equal to the given sum and return such subsets count. This approach will have exponential time complexity.
Definition in file subset_sum.cpp.
int main | ( | void | ) |
Main function.
Definition at line 104 of file subset_sum.cpp.
uint64_t backtracking::subset_sum::number_of_subsets | ( | int32_t | sum, |
const std::vector< int32_t > & | in_arr ) |
The main function implements count of subsets.
sum | is the required sum of any subset |
in_arr | is the input array |
Definition at line 34 of file subset_sum.cpp.
|
static |
Test implementations.
Definition at line 58 of file subset_sum.cpp.