R
rahul
Given buffer of varying sizes, I have to combine them into one big
block of size MAX using min. number of individual buffer blocks.
Consider:
#define MAX 64
int a[LEN] = {30, 50, 20, 14, 30, 4, 19, 20, 11, 24};
The solution for this case will be
idx size
1 50
3 14
So, I will be combining 1 and 3 to obtain a block of 64 KB. Here is my
solution for this:
http://rahulkmr.pastebin.com/m68768ce1
IMO, the only solution to this problem involves generating all
combinations, filtering them on which one sums to MAX and then
selecting the combination with min. items. I can follow the greedy
approach, but I don't think it is going to yield any better results.
My solution is O(n^3). I would like to know if it can be further
optimized without convoluting it.
Rahul
block of size MAX using min. number of individual buffer blocks.
Consider:
#define MAX 64
int a[LEN] = {30, 50, 20, 14, 30, 4, 19, 20, 11, 24};
The solution for this case will be
idx size
1 50
3 14
So, I will be combining 1 and 3 to obtain a block of 64 KB. Here is my
solution for this:
http://rahulkmr.pastebin.com/m68768ce1
IMO, the only solution to this problem involves generating all
combinations, filtering them on which one sums to MAX and then
selecting the combination with min. items. I can follow the greedy
approach, but I don't think it is going to yield any better results.
My solution is O(n^3). I would like to know if it can be further
optimized without convoluting it.
Rahul