hdu 1081 To The Max

来源:互联网 发布:统计数据软件 编辑:程序博客网 时间:2024/05/18 01:38

http://acm.hdu.edu.cn/showproblem.php?pid=1081

#include <cstdio>#include <cstring>#include <algorithm>#define maxn 300using 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;}


0 0
原创粉丝点击