有氧100pts,无氧80pts求助!
查看原帖
有氧100pts,无氧80pts求助!
704634
poor_OIer楼主2024/7/28 22:07
#include<bits/stdc++.h>
using namespace std;
int n,a[125][125],tot[125][125][125],ans=-1828810;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')
			f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
int main()
{
	n=read();
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			a[i][j]=read(),tot[i][1][j]=a[i][j]+tot[i][1][j-1];
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			for(int k=1;k<n;k++)
				tot[i][k][j]=tot[i][1][j]-tot[i][1][k];
		}
	}
	for(int fromi=1;fromi<=n;fromi++)
		for(int fromj=1;fromj<=n;fromj++)
			for(int toi=fromi;toi<=n;toi++)
				for(int toj=fromj;toj<=n;toj++)
				{
					int sum=0;
					for(int i=fromi;i<=toi;i++)
						sum+=tot[i][fromj][toj];
					if(sum>ans)
						ans=sum;
				}
	cout<<ans;
	return 0;
}
2024/7/28 22:07
加载中...