|
ADS
Algorithms and Data Structures
|
The linear partition problem (also the painter's partition, or the bottleneck partition of a chain): the items \( A[ 0 .. n - 1 ] \) split into \( k \) contiguous parts so that the largest sum of a part is the least, e.g., \( n \) boards of lengths \( A_i \) to be painted by \( k \) painters, each one a block of consecutive boards, in the least time. More...
#include "ADS/Contract.h"#include <algorithm>#include <concepts>#include <cstddef>#include <utility>#include <vector>#include "ADS/optimization/impl/LinearPartition.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| template<class T> | |
| std::pair< T, std::vector< std::size_t > > | ADS::linearPartition (const std::vector< T > &A, std::size_t k) |
| the least largest sum of a part over the splits of \( A \) in \( k \) nonempty contiguous parts, and the starts of the parts after the first one | |
| template<std::integral T> | |
| T | ADS::painterPartition (const std::vector< T > &A, std::size_t k) |
| the least largest sum of a part over the splits of \( A \) in at most \( k \) contiguous parts; 0 for \( A \) empty | |
The linear partition problem (also the painter's partition, or the bottleneck partition of a chain): the items \( A[ 0 .. n - 1 ] \) split into \( k \) contiguous parts so that the largest sum of a part is the least, e.g., \( n \) boards of lengths \( A_i \) to be painted by \( k \) painters, each one a block of consecutive boards, in the least time.
In the literature, the problem on a chain of \( n \) items is solved in \( O( n ) \) time for \( k \) fixed, and in \( O( n + k^2 \log^2 n ) \) in general, by parametric search on the prefix sums (Frederickson); the dynamic programming above has the quadrangle inequality, so that the monotone cuts of Knuth and Yao bring it to \( O( k n ) \) for items not negative.
The contracts [see Contract.h]: \( 1 \le k \le n \) for linearPartition(), and its cuts give the cost found (checked at level 3); \( k \ge 1 \) and the items not negative for painterPartition(). The functions are defined in LinearPartition.tpp.