最大连续子序列和
int MaxSubseqSum(int a[], int n)
{
int max = a[0];
int sum = 0;
for (int i = 0; i < n; ++i)
{
sum += a[i];
if (sum < 0) sum = 0;
if (sum > max)
{
max = sum;
}
}
return max;
}
int MaxSubseqSum(int a[], int n)
{
int max = a[0];
int sum = 0;
for (int i = 0; i < n; ++i)
{
sum += a[i];
if (sum < 0) sum = 0;
if (sum > max)
{
max = sum;
}
}
return max;
}