Optimization of Multiple backpack

orz zrf

First of all, the classic multi backpack solution, is putting an item into the total number of copies of the article, and then do 01 backpack

The first method is to optimize it into an item O ( l O g ( That object Article ) ) O (log (total number of parts of the article)) , for example:

If there are items 2 n 1 2^n-1 th, split into 2 0 , 2 1 , . . . , 2 n 1 2^0,2^1,...,2^{n-1} , so that if it is not. 2 n 1 2^n-1 , to find the greatest 2 n 1 2^n-1 , such that 2 n 1 < = 2 ^ n-1 <= Total , and then divided into 2 0 , 2 1 , 2 2 , . . . 2 ( n 1 ) , ( 2 n 1 ) 2 ^ 0,2 ^ 1,2 ^ 2, ... 2 ^ (n-1), the total number of - (2 ^ n-1) these parts. Backpack and then again 01

The second queue is monotonic

May first be found that for a fixed items i, and a fixed current capacity j, can be found can be transferred to j forms an arithmetic sequence, tolerances are individual volumes vi I article then can the volume according to vi modulo remainder classification, and then can be transferred to the equivalent for class i, the number of which is assumed j , j v i , j 2 v i , . . . , j k v i j, j-vi, j-2 * vi ... jk * vi , each of the first position to a different weight value of i, but the observation that if the number of subtracting each k w i k*wi , then proceeds to transfer the weight of the i on the same, can be obtained directly monotonically queue.

Published 62 original articles · won praise 1 · views 1005

Guess you like

Origin blog.csdn.net/wmhtxdy/article/details/103735845