第六讲 代码优化30036.pptVIP

  • 1
  • 0
  • 约4.39千字
  • 约 18页
  • 2016-09-21 发布于江西
  • 举报
第六讲 代码优化30036.ppt

第六讲 专题解析 ——代码优化 The Problem and a Simple Program The problem arose in one-dimensional pattern recognition 输入是n维实数数组x; 输出连续子数组的和为最大的(最大字段和). 例如,输入数组如下: 则返回子数组 X[3 .. 7], 和为 187. Simple Program The obvious program for this task is simple: for each pair of integers L and U (where 1 L U N), compute the sum of X[L.. U] and check whether that sum is greater than the maximum sum so far. The pseudocode given in Algorithm, it executes is O(N3). MaxSoFar = 0 for i = [0, n) for j = [i, n) sum = 0 for k = [i, j] sum += x[k] /* Sum now contains the sum of X[i..j] */

文档评论(0)

1亿VIP精品文档

相关文档