跳到正文

个人记录

二维前缀和 模板

AuFu约 1 分钟
原文
文章信息与版本

文章信息

收录
2026年1月24日
更新
2026年5月23日
篇幅
约 1 分钟

版本

  1. v1当前

本蒟蒻笑穴僧发文章了哈哈!!!!!!!!

代码模板:P1719

100AC Code:

C++
#include <bits/stdc++.h>
using namespace std;
int n;
int a[1145][1145];
int c[1145][1145];
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0),cout.tie(0);
	cin>>n;
	for(int i=1;i<=n;i++){
		for(int j=1;j<=n;j++){
			cin>>a[i][j];
			c[i][j]=c[i][j-1]+c[i-1][j]-c[i-1][j-1]+a[i][j];
		}
	}
	int maxe=0;
	for(int i1=1;i1<=n;i1++){
		for(int j1=1;j1<=n;j1++){
			for(int i2=i1;i2<=n;i2++){
				for(int j2=j1;j2<=n;j2++){
					int s=c[i2][j2]-c[i2][j1-1]-c[i1-1][j2]+c[i1-1][j1-1];
					maxe=max(maxe,s);
				}
			}
		}
	}
	cout<<maxe;
}
原文