|
ADS
Algorithms and Data Structures
|
Two problems of dynamic programming on a row of \( n \) houses, where the choice of each house depends only on the one of its neighbor: More...
#include "ADS/Contract.h"#include <algorithm>#include <cstddef>#include <utility>#include <vector>#include "ADS/optimization/impl/HouseProblems.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Functions | |
| template<class T> | |
| T | ADS::maxNonAdjacentSum (const std::vector< T > &A) |
| the largest sum of items of \( A \) no two of them adjacent, 0 for none | |
| template<class T> | |
| std::pair< T, std::vector< std::size_t > > | ADS::nonAdjacentSelection (const std::vector< T > &A) |
| the sum of maxNonAdjacentSum() and the places of its items, increasing; an item is taken only if it makes the sum larger | |
| template<class T> | |
| std::pair< T, std::vector< std::size_t > > | ADS::paintHouses (const std::vector< std::vector< T > > &cost) |
| the least cost of a painting of the houses, adjacent houses of different colors, \( \mathit{cost}[ h ][ c ] \) for the house \( h \) of the color \( c \), and the colors | |
Two problems of dynamic programming on a row of \( n \) houses, where the choice of each house depends only on the one of its neighbor:
Both are shortest paths in the DAG of the states (house, choice), and generalize to a tree of houses by the same recurrence on the children.
The contracts [see Contract.h]: the rows of cost have the same number \( k \) of colors, \( k \ge 2 \) for two houses or more; the places chosen are increasing and not adjacent, the colors of adjacent houses differ, and both give the value found. The functions are defined in HouseProblems.tpp.