0001 extern int s_lo, s_hi; 0002 0003 int gs_IC( int A[], int n ) { //递增策略:O(n^2) 0004 int gs = A[0]; s_lo = 0; s_hi = 1; 0005 for ( int lo = 0; lo < n; lo++ ) { //枚举所有起始于lo 0006 for ( int s = 0, hi = lo; hi < n; ) { //终止于hi的区间 0007 s += A[hi++]; //递增地得到其总和:O(1) 0008 if ( gs < s ) 0009 { gs = s; s_lo = lo; s_hi = hi; } //择优、更新 0010 } 0011 } 0012 return gs; 0013 }