#include<stdio.h>
#include<stdlib.h>
/*!\func int MaxSubsequenceSum(const int a[],int n)
*\bref the problem about the max sum of subsequence
*\para[in] a[] : the sequence
*\para[in] n : the number of sequence
*\author zhangdy
*\date 2010-06-01
*\return int : the max num of subsequence
*/
int MaxSubsequenceSum(const int a[],int n)
{
int max = 0,sum = 0,i;
for(i=0;i<n;i++)
{
sum += a[i];
if(sum > max)
{
max = sum;
}
else if(sum < 0)
{
sum = 0;
}
}
return max;
}
/*! main func */
int main()
{
int a[] = {1,-2,3,8,-5,2,5,4,9,-11,22,31,23,-3,-31,-22,4};
int i;
int n = sizeof(a)/sizeof(int);
printf("a[]=");
for(i=0;i<n;i++)
{
static char separator = '{';
printf("%c%d",separator,a[i]);
separator = ',';
}
printf("}\n");
printf("the max sum is : %d",MaxSubsequenceSum(a,n));
system("pause");
return 0;
}