先写两重循环枚举起点行k1到终点行k2,再写一个循环遍历每列i,将列i压缩成一个数字,它表示第i列k1~k2行的前缀和(用二维前缀和预处理),那么就变成了一个1*n的矩阵,即一个一维数组,然后求其最大子段和,同时取max即可。时间复杂度O(n^3)。 #include <bits/stdc++.h> using namespace std; const int N=510,inf=1e18; typedef long long ll; ll a[N][N],sum[N][N],dp[N]; int main() { ios::sync_with_stdio(false); int ...