https://leetcode.com/problems/max-sum-of-rectangle-no-larger-than-k/description/
class Solution {
public:
int maxSumSubmatrix(vector<vector<int>>& matrix, int k) {
if(matrix.size()<=0) return 0;
int row = matrix.size(), col = matrix[0].size();
vector<vector<int>> dp(row+1, vector<int>(col+1, 0));
for(int i=1; i<=row; i++){
for(int j=1; j<=col; j++){
dp[i][j] = matrix[i-1][j-1]+ dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1];
}
}
int res = INT_MIN;
for(int i=1; i<=row; i++){
for(int j=1; j<=col; j++){
for(int ii=0; ii<i; ii++){
for(int jj=0; jj<j; jj++){ //计算(ii,jj)到(i,j)围成的矩形面积
int one = dp[i][j]-dp[ii][j] - (dp[i][jj]-dp[ii][jj]);
if(one <=k){
res = max(res, one);
}
}
}
}
}
return res;
}
};