A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://TheAlgorithms.github.io/C-Plus-Plus/de/d8c/partition__problem_8cpp_source.html below:

TheAlgorithms/C++: dynamic_programming/partition_problem.cpp Source File

45namespace

partitionProblem {

54bool

findPartiion(

const

std::vector<uint64_t> &arr, uint64_t size) {

55

uint64_t sum = std::accumulate(arr.begin(), arr.end(),

61

std::vector<bool> part;

65 for

(uint64_t it = 0; it <= sum / 2; ++it) {

66

part.push_back(

false

);

70 for

(uint64_t it = 0; it < size; ++it) {

72 for

(uint64_t it2 = sum / 2; it2 >= arr[it];

75 if

(part[it2 - arr[it]] == 1 || it2 == arr[it]) {

90

std::vector<uint64_t> arr = {{1, 3, 3, 2, 3, 2}};

91

uint64_t n = arr.size();

92 bool

expected_result =

true

;

93 bool

derived_result = dp::partitionProblem::findPartiion(arr, n);

94

std::cout <<

"1st test: "

;

95

assert(expected_result == derived_result);

96

std::cout <<

"Passed!"

<< std::endl;

static void test()

Self-test implementations.

int main()

Main function.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4