您的位置:首页 > 其它

hdu 1081 To The Max

2014-04-04 20:47 330 查看
http://acm.hdu.edu.cn/showproblem.php?pid=1081

#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 300
using namespace std;
const int inf=0x7fffffff;

int dp[maxn][maxn];
int a[maxn][maxn];

int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
for(int i=1; i<=n; i++)
{
dp[i][0]=0;
for(int j=1; j<=n; j++)
{
scanf("%d",&a[i][j]);
dp[i][j]=dp[i][j-1]+a[i][j];
}
}
int max1=-inf;
for(int i=1; i<=n; i++)
{
for(int j=1; j<=i; j++)
{
int c=0;
for(int k=1; k<=n; k++)
{
c+=(dp[k][i]-dp[k][j-1]);
if(max1<c)
max1=c;
if(c<0)
c=0;
}
}
}
printf("%d\n",max1);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: