#include < iostream .h > //动态规划算法,求大子段问题,详见视频教程int MaxSum(int n,int a[]){ int sum=0,b=0; for(int i=0;i < n ;i++) { if(b > 0) b+=a[i]; else b=a[i]; if(b>sum) sum=b; } return sum;}void main(){ int a[]={-2,11,-4,13,-5,-2}; cout < <"最大子段和为: "<<MaxSum(6,a)<<endl; }