`

最大子列和问题(20) - 中国大学MOOC-陈越、何钦铭-数据结构基础习题集

 
阅读更多
#include <iostream>

long maxSubSum2(int A[] ,int N) 
{ 
  int thisSum , maxSum =0;
  int i,j;
  for (int i = 0; i < N; i++) 
  {
    int thisSum = 0; 
    for (int j = i; j < N; j++) 
    { 
      thisSum += A[j]; 
      if (thisSum > maxSum) 
        maxSum = thisSum; 
     } 
  } 
  return maxSum; 
}

int main(){
  int n=0;
  scanf("%d",&n);
  int *number=new int[n]; 
  for(int i=0;i<n;++i)
       scanf("%d ",&number[i]);
  int maxsum = 0;
  maxsum = maxSubSum2(number,n);
  printf("%d",maxsum);
}

 

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics