ural 1146. Maximum Sum

http://acm.timus.ru/problem.aspx?space=1&num=1146

 1 #include <cstdio>
 2 #include <cstring>
 3 #include <algorithm>
 4 #define maxn 200
 5 using namespace std;
 6 
 7 const int inf=0x7fffffff;
 8 int dp[maxn][maxn],a[maxn][maxn];
 9 
10 int main()
11 {
12     int n;
13     scanf("%d",&n);
14     for(int i=1; i<=n; i++)
15     {
16         dp[i][0]=0;
17         for(int j=1; j<=n; j++)
18         {
19             scanf("%d",&a[i][j]);
20             dp[i][j]=dp[i][j-1]+a[i][j];
21         }
22     }
23     int max1=-inf;
24     for(int i=1; i<=n; i++)
25     {
26         for(int j=1; j<=i; j++)
27         {
28             int c=0;
29             for(int k=1; k<=n; k++)
30             {
31                 c+=dp[k][i]-dp[k][j-1];
32                 max1=max(max1,c);
33                 if(c<0) c=0;
34             }
35         }
36     }
37     printf("%d\n",max1);
38     return 0;
39 }
View Code

 

posted @ 2014-03-27 21:11  null1019  阅读(147)  评论(0编辑  收藏  举报