Wednesday, November 2, 2011

Linear programming: maximal sum of subsequence

maxim_subsequence( int num_arr[]; int size)
{
  int sum=0;
  int sum_max = 0;

  for(int i=0; i
 {
    sum +=num_arr[i];
    if(sum>sum_max)
      sum_max = sum;
   else if(sum<0) //sum will not contribute to new maximum subsequence.
         sum=0;
}
  return sum_max;
}

No comments: