- 最大连续子序列之和
-
//一维最大连续子序列之和 int maxSubSequence(int n) { int res = 0; for (int i = 0; i < n; i++) { if (i == 0) { dp[i] = A[i]; } else { dp[i] = max(A[i], dp[i - 1] + A[i); } if (dp[i] > res) { res = dp[i]; } } return res; }
- 最大子矩阵之和
//一维最大连续子序列之和 int maxSubSequence(int n) { int res = 0; for (int i = 0; i < n; i++) { if (i == 0) { dp[i] = A[i]; } else { dp[i] = max(A[i], dp[i - 1] + A[i); } if (dp[i] > res) { res = dp[i]; } } return res; }