1 条题解

  • 0
    @ 2026-10-25 15:08:46

    思路

    枚举行边界压缩成非空最大子段和,正确处理全负矩阵。

    参考程序(C++11)

    #include <bits/stdc++.h>
    using namespace std;
    int main(){int n;cin>>n;vector<vector<int>>a(n,vector<int>(n));for(auto &r:a)for(int &x:r)cin>>x;int best=INT_MIN;for(int top=0;top<n;top++){vector<int>s(n);for(int bottom=top;bottom<n;bottom++){for(int j=0;j<n;j++)s[j]+=a[bottom][j];int cur=s[0];best=max(best,cur);for(int j=1;j<n;j++){cur=max(s[j],cur+s[j]);best=max(best,cur);}}}cout<<best<<'\n';}
    
    • 1

    信息

    ID
    1120
    时间
    1000ms
    内存
    64MiB
    难度
    普及
    标签
    递交数
    1
    已通过
    1
    上传者