using namespace std;
// 最大子数组
int findDp(int a[], int n){
if(n==0){
return 0;
}
int max = a[0], sum = 0, ind = -1;
for (int i = 0; i < n; ++i) {
if(sum > 0){
sum += a[i];
}else{
sum = a[i];
}
if(sum > max){
max = sum;
// ind = i;
}
}
return max;
}
// 最大子矩阵
void findmatrix(int a[][3], int row, int col){
int sr = 0, t = 0, max = -1, sumJ[col];
// 起始行
while (sr < row){
fill(sumJ, sumJ + col, 0);
for (int i = sr; i < row; ++i) {
for (int j = 0; j < col; ++j) {
sumJ[j] += a[i][j];
}
t = findDp(sumJ, col);
if(t > max){
max = t;
}
}
sr++;
}
printf("%d\n", max);
}
int main(){
int a[][3] = {
{-1, -1, -1},
{-1, 2, 2},
{-1, -1, -1},
};
int p[] = {1, -2, 3, 5, -2, 6, -1};
printf("%d\n", findDp(p, 7));
findmatrix(a, 3, 3);
return 0;
}