Help needed for Multiple Knapsack optimization

Hello,

I found this optimization for Multiple Knapsack Knapsack Problem - Algorithms for Competitive Programming. I think that there is issue because taking a bundle of size ki−(2⌊log2⁡(ki+1)⌋−1) will result in not all number of counts being considered. For example if some item can be selected max 9 times, (j∈[0,⌊log2⁡(ki+1)⌋−1]) will result in j between 0 and 2 (inclusive). It means that we will test all possible counts up to 7 in that case, but now using the bundle of size 2 will skip testing the case where 8 is optimal count for that item.

Am I missing something in my reasoning?

9 is split into 1+2+4+2, and 2+4+2=8.

1 Like

Oh I see, we split the reminder to powers of 2 as well. Thank you! Then this impl to split in the groups is not correct because it just adds the whole reminder ( ki−(2⌊log2⁡(ki+1)⌋−1)) without splitting it in powers of 2 Knapsack Problem - Algorithms for Competitive Programming

index = 0;
for (int i = 1; i <= n; i++) {
int c = 1, p, h, k;
cin >> p >> h >> k;
while (k > c) {
k -= c;
list[++index].w = c * p;
list[index].v = c * h;
c *= 2;
}
list[++index].w = p * k;
list[index].v = h * k;
}

No, the remainder is not split into powers of 2. It just so happens that for 9 the remainder is a power of 2.