矩阵中最大的二维矩阵

来源:互联网 发布:冲牙器 知乎 编辑:程序博客网 时间:2024/05/08 00:07
求一个矩阵中最大的二维矩阵(元素和最大).如:
1 2 0 3 4
2 3 4 5 1
1 1 5 3 0
中最大的是:
4 5
5 3
作者: 天才小喵
链接:http://www.imooc.com/article/4313
来源:慕课网
求一个矩阵中最大的二维矩阵(元素和最大).如:
1 2 0 3 4
2 3 4 5 1
1 1 5 3 0
中最大的是:
4 5
5 3
作者: 天才小喵
链接:http://www.imooc.com/article/4313
来源:慕课网
求一个矩阵中最大的二维矩阵(元素和最大).如:
1 2 0 3 4
2 3 4 5 1
1 1 5 3 0
中最大的是:
4 5

5 3

int fun(vector<vector<int> > &a){int m = a.size();int n = a[0].size();int buf[m][n];for (int i = 1; i < m; i++){buf[i][1] = a[i-1][0] + a[i-1][1] + a[i][0] + a[i][1];for (int j = 2; j < n; j++){buf[i][j] = buf[i][j-1] + a[i-1][j] + a[i][j];}}int result = INT_MIN;for (int i = 1; i < m; i++){if (buf[i][1] > result){result = buf[i][1];}for (int j = 2; j < n; j++){int temp = buf[i][j] - buf[i][j-2];if (temp > result){result = temp;}}}return result;}



0 0