The Basic idea is to use the Maximum subarray solution to generate all subarray of an array. But in order to implement that idea, I have been hit with a roadblock where I need to find all combinations of two vectors(left side of the mid and right side of the mid).
For example, if there are 5 elements in each of these vectors then if I choose 1 element from vector1 and then I have to choose one to five elements from vector2.
Similarly, if I choose 2 elements from vector1 then I have to choose one to five elements from vector2 etc.
The below is my try to implement the subarray for left and right sides.I need your help in implementing combinations of two vectors in c++.
for (int i = m; i >= l; i--) {
sum = sum + arr[i];
A[cnt].push_back(arr[i]);
if (sum > left_sum)
left_sum = sum;
}
int zsize=A[cnt].size();
int k1=cnt;
cnt++;
for (int i=0;i<zsize-1;i++)
{
A[cnt]=A[k1];
A[cnt].erase(A[cnt].begin()+i+1,A[cnt].begin()+zsize);
cnt++;
}