60分求助

P1719 最大加权矩形

BestCat2023 @ 2023-10-02 10:12:06

记录:https://www.luogu.com.cn/record/126990094

代码:

#include<iostream>
using namespace std;
typedef long long ll;
const int N=125;
int n;
int a[N][N],s[N][N];
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
            s[i][j]=s[i-1][j]+s[i][j-1]-s[i-1][j-1]+a[i][j];
        }
    }
    int mx=-1;
    for(int x1=1;x1<=n;x1++){
        for(int y1=1;y1<=n;y1++){
            for(int x2=1;x2<=n;x2++){
                for(int y2=1;y2<=n;y2++){
                    mx=max(mx,s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1]);
                }
            }
        }
    }
    cout<<mx;
    return 0;
}

求大佬指点


by Xuyiyao2010 @ 2023-10-13 22:29:51

打错了 if(x2<x1||y2<y1) continue;


|