I have an ordered list of weighted items, the weight of each is less than or equal to N. I need to convert it to a list of clusters. Each cluster should cover several consecutive elements, and the total cluster weight should be less than or equal to N.
Is there an algorithm that does this, minimizing the total number of clusters and keeping their weights as large as possible?
eg. ([a], 5), (b, 1), (c, 2), (d, 5)], N = 3), ([d], 5)]
, "" , Knuth (http://en.wikipedia.org/wiki/Word_wrap), . badness ( ) ( ).
.
, , . , .
, : [(a, 1), (b, 1), (c, 1), (d, 1), (e, 1)], N = 2
- [([a], 1), ([b], 1), ([c], 1), ([d], 1), ([e], 1)]
- [([a, b], 2), ([c, d], 2), ([e], 1)]
, ( ) ? , .
, 2k + 1 N/2. , k + 1 (k 2 1 1) N/2 . 2k + 1 1 , .
: , "" . ?
Source: https://habr.com/ru/post/1756988/More articles:ParamArray does not work with COM - .netElegant interface for associations with a lot of data - user-interfaceКак мы должны захватить пользователя базы данных при использовании структуры сущности на среднем уровне? - securityQuick string search such as startsWith () not equals () - javaExecute As SQL Command and Linq to SQL - c #Как использовать ASCIIFoldingFilter в моем приложении Lucene? - javaZend Framework and prevention of fat controllers - phpSQL - When will an empty OVER clause be used? - sqllatex link separately compiled book - latexHow can I store music on my Android phone without letting the user download and use it? - androidAll Articles