标签:blog cto nbsp off vector 模式识别 计算机 ems 动态
1 class Solution { 2 public: 3 //dp[i] = array[i] i==0 || dp[i-1]<0 4 //dp[i] = dp[i-1] + array[i] i != 0 && dp[i-1] > 0 5 int FindGreatestSumOfSubArray(vector<int> array) { 6 int length = array.size(); 7 if(array.empty() || length <=0) 8 return 0; 9 int dp[length]; 10 memset(dp,0,length); 11 dp[0] = array[0]; 12 int maxSum = 0x80000000; 13 for(int i=1;i<length;i++) 14 { 15 if(dp[i-1] > 0) 16 { 17 dp[i] = dp[i-1] + array[i]; 18 } 19 else 20 { 21 dp[i] = array[i]; 22 } 23 if(dp[i] > maxSum) 24 { 25 maxSum = dp[i]; 26 } 27 } 28 return maxSum; 29 } 30 };
标签:blog cto nbsp off vector 模式识别 计算机 ems 动态
原文地址:http://www.cnblogs.com/qqky/p/6931976.html