60求调

P1719 最大加权矩形

GECSD @ 2024-11-12 17:32:11

#include <bits/stdc++.h>
#define llong long long
using namespace std;
const int give_long=120+10;
int n;
llong answer=LLONG_MIN;
int a[give_long][give_long],s[give_long][give_long];
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]
            +a[i][j]-s[i-1][j-1];
        }
    for(int x=1;x<=n;x++)
        for(int y=1;y<=n;y++)
            for(int xx=1;xx<=n;xx++)
                for(int yy=1;yy<=n;yy++)
                {
                    llong anser=s[xx][yy]-
                    s[xx][y-1]-s[x-1][yy]
                    +s[x-1][y-1];
                    if(answer<anser)
                        answer=anser;
                }
    cout<<answer<<"\n";
    return 0;
}

by gaoju @ 2024-11-24 10:15:59

xx从x开始,yy同理


by gaoju @ 2024-11-25 17:24:46

求加团地址


by Lanhening @ 2024-11-27 20:58:59


#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstdio>
#include<algorithm>
using namespace std;
long long pre[150][150],a[150][150];
int main(){
    long long n,maxx=-1,t;
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            cin>>a[i][j];
            pre[i][j]=pre[i-1][j]+pre[i][j-1]-pre[i-1][j-1]+a[i][j];
        }
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=i;k++){
                for(int m=1;m<=j;m++){
                    t=pre[i][j]-pre[k-1][j]-pre[i][m-1]+pre[k-1][m-1];
                    if(t>maxx) maxx=t;
                }
            }
        }
    }
    cout<<maxx<<endl;
    return 0;
}

|