样本答案是15,而我的是13;大佬们,问题出在哪了

P1719 最大加权矩形

apengya @ 2021-11-27 19:45:10

#include<iostream>
#include<algorithm>
using namespace std;
int n,f,maxx=-999999;
int a[130][130]={0};
int qz[130][130]={0};
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            cin >> a[i][j];
            qz[i][j] = qz[i-1][j] + a[i][j]+qz[i][j-1]-qz[i-1][j-1];
        }
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = 1; j <= n; j++)
        {
            for (int k = i; k <= n; k++)
            {
                for (int o = j; o <= n; o++)
                {
                    f = qz[k][o] +qz[i - 1][j - 1]-qz[i][j-1]-qz[i-1][j];
                    maxx = max(f, maxx);
                }
            }
        }
    }
    cout << maxx<<endl;
    return 0;
}

by lsj2009 @ 2021-11-27 20:13:34

@apengya qz[k][o] +qz[i - 1][j - 1]-qz[i][j-1]-qz[i-1][j]应该是qz[k][o] +qz[i - 1][j - 1]-qz[k][j-1]-qz[i-1][o]


by lsj2009 @ 2021-11-27 20:15:09

看看这图


by apengya @ 2021-11-27 20:26:28

@lsj2009 哦吼,懂了懂了帅哥


|