Trying to use divide and conquer to get all subarrays of an array

  c++, combinations, sub-array, vector

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).

The below is my try to implement the subarray for left and right side.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++;
}

Source: Windows Questions C++

LEAVE A COMMENT