I searched for a bit, found a good blog, said very detailed: link.
Analytical
The most primitive state transfer equation for multiple backpacks:
Make c[i] = min (Num[i], j/v[i])
F[I][J] = max (F[i-1][j-k*v[i]] + k*w[i]) (1 <= k <= C[i]) k here refers to the first item of the article I k pieces.
If you make a = J/v[i], B = J V[i] Then J = A * V[i] + b.
Here the meaning of K is changed, k means that the number of items to take the article I is less than a few.
Then f[i][j] = Max (F[i-1][b+k*v[i]]-k*w[i]) + A*w[i] (A-c[i] <= K <= a)
It can be found that f[i-1][b+k*v[i]]-k*w[i] is only related to K, and this k is a continuous one. All we have to do is find out the maximum value of f[i-1][b+k*v[i]]-k*w[i] When K is within the feasible interval.
This enables the use of Monotonic queue optimization.
Code
O (NM) multi-pack algorithm optimized with monotone queue