蓝桥杯计蒜客最大子阵

#include <iostream>
#include <cstdio>
using namespace std;
int a[55][55];
int ans=-10005;
int main()
{
	//n行m列 
	int n,m;
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>a[i][j];
		}
	}
	//分别暴力枚举上下左右四个边界 
	for(int i=0;i<n;i++)
	{
		for(int j=i;j<n;j++)
		{
			for(int l=0;l<m;l++)
			{
				for(int k=l;k<m;k++)
				{
					int temp=0;
					for(int x=i;x<=j;x++)
					{
						for(int y=l;y<=k;y++)
						{
							temp+=a[x][y];
						}
					}
					if(temp>ans)
					ans=temp;
				}
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_39903708/article/details/86311172