using System.Collections.Generic;
using System.Text;
namespace maxSubsequenceSum_n3
{
//求最大连续子序列之和的立方算法。
//a是待分析数组,试举例。
class Program
{
static void Main(string[] args)
{
int[] a = new int[10]
{14,57,3,1,-58,-67,-9,0,78,444};
int maxSum = 0;
int thisSum = 0;
int a_lengh = a.Length;//获取a的数组长度
for (int i=0;i<a_lengh ;i++ )
{
for (int j=i;j<a_lengh ;j++ )
{
//此时已经获取一个子序列,求其和
thisSum = 0;
for (int k = i; k <= j; k++)
{
thisSum += a[k];
}
if (thisSum > maxSum)
maxSum =thisSum ;
}
}
Console.WriteLine("最大连续子序列之和为:{0}",maxSum );
Console.Read();
}
}
}