dp1 最大子矩阵

///比赛想了好长时间的最大子矩阵...出来看看题解才懂,自己真蠢= =

#include <algorithm>
#include <stack>
#include <istream>
#include <stdio.h>
#include <map>
#include <math.h>
#include <vector>
#include <iostream>
#include <queue>
#include <string.h>
#include <set>
#include <cstdio>
#define FR(i,n) for(int i=0;i<n;i++)
#define MAX 2005
#define mkp pair <int,int>
using namespace std;
const int maxn = 2e2 + 3;
typedef long long ll;

void read(int &x) {
char ch; bool flag = 0;
for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
x *= 1 - 2 * flag;
}

int sum[maxn][maxn];
int arr[maxn][maxn];
int main() {
int n;
while(~scanf("%d",&n))
{
memset(sum,0,sizeof(sum));
for(int i=1;i<=n;i++)
{
for(int j=1;j<=n;j++)
{
scanf("%d",&arr[i][j]);
sum[i][j]=arr[i][j]+sum[i][j-1];
}
}
int ans=-0x3f;
///cout<<ans<<endl;
for(int i=1;i<=n;i++)
{
for(int j=i;j<=n;j++)
{
int sub=0;
for(int m=1;m<=n;m++)
{
if(sub<0)sub=0;
sub+=sum[m][j]-sum[m][i-1];
ans=max(sub,ans);
}
}
}
cout<<ans<<endl;
}
return 0;
}

猜你喜欢

转载自www.cnblogs.com/DreamKill/p/9164930.html
今日推荐