#include "MaxSubsequenceSum.h"
int64_t MaxSubsequenceSum(const int32_t arg[], const uint32_t length)
{
int64_t ThisSum = 0, MaxSum = 0;
for (uint32_t i = 0; i < length; i++)
{
ThisSum += arg[i];
if (ThisSum >= MaxSum)
{
MaxSum = ThisSum;
}
else if (ThisSum < 0)
{
ThisSum = 0;
}
}
printf("Max Subsequence Sum is %d!\r\n", MaxSum);
return MaxSum;
}
最大子序列和问题
最新推荐文章于 2024-09-06 16:35:02 发布