#include<stdio.h>
int MaxS(int *a, int n)
{
int sum = 0;
int max = 0;
for (int i = 0; i < n; i++)
{
if (sum < 0)
sum = a[i];
else
sum += a[i];
if (sum>max)
max = sum;
}
return sum;
}
int main()
{
int a[] = { -2, -11, -4, 13, -5, -2 };
printf("%d", MaxS(a, 6));
}
有正有负的整数数组,找出总和最大的连续数列(动态规划)
最新推荐文章于 2022-12-07 10:22:25 发布
![](https://img-home.csdnimg.cn/images/20240711042549.png)