Prob.3 [+ dimensional prefix and violence] Luo Gu 2280HNOI2003 laser bomb Upd: 2020.3.1

1. prefix and S = Σ (i = 1 to n) ai

2. two 维前 缀和 S [i] [j] = S [i-1] [j] + s [i] [j-1] -S [i-1] [j-1] + A [i] [j];

And evaluates the number of the rectangle (L, R), set top right coordinates (x, y) Sum = S [x] [y] -S [xL] [y] -S [x] [yR] + S [xL] [yR];

FIG For this, we need only O (n ^ 2) pretreatment of all of the prefix and a two-dimensional, and O (n ^ 2) enumerate a top right corner of each square, to record the value.

AC Code:

#include<cstdio>
using namespace std;
int s[5002][5002],n,R,x,y,z,Ans;
inline int max(int x,int y)
{
return x>y?x:y;
}
int main()
{
scanf("%d%d",&n,&R);
for(int i=1;i<=n;i++)
{
scanf("%d%d%d",&x,&y,&z);
s[x+1][y+1]=z;
}
for(int i=1;i<=5001;i++)
for(int j=1;j<=5001;j++)
s[i][j]+=s[i-1][j]+s[i][j-1]-s[i-1][j-1];
for(int i=R;i<=5001;i++)
for(int j=R;j<=5001;j++)
Ans=max(Ans,s[i][j]-s[i-R][j]-s[i][j-R]+s[i-R][j-R]);
printf("%d",Ans);
return 0;
}

Guess you like

Origin www.cnblogs.com/little-cute-hjr/p/12391287.html
upd