CODEVS——T 3736 【HR】万花丛中2

http://codevs.cn/problem/3736/

 时间限制: 1 s
 空间限制: 128000 KB
 题目等级 : 黄金 Gold
 
 
 
题目描述 Description

   HR神犇在成功攻略ZX后,花心的他举办了一届选(yu)美(yue)大赛。

   由于HR神犇有重度不规则形体恐惧症,所以他要求选美的女孩纸要站成一个正方形。因为HR神犇的眼光是非常之高的,所以他要求选出来的女孩美貌值总和最大,由于HR神犇的精力非常多,所以选出来的女孩数量没有限制。当然,一些女孩纸比较丑,美貌值可能为负数。而且,HR神犇的重度不规则形体恐惧症使他要求选出来的女孩纸形成一个矩形(不是正方形)(实心的)。

   HR神犇决定,只要你成功帮他找出这个矩形,他就给你10000000000 mod 10元。

 

输入描述 Input Description

第一行一个整数n,表示正方形的边长。

接下来n行,每行n个整数,表示每个女孩的美貌值。

输出描述 Output Description

输出只有一个整数,表示最大的美貌值总和。

样例输入 Sample Input

4

0 -2 -7 0

9 2 -6 2

-4 1 -4 1

-1 8 0 -2

 

样例输出 Sample Output

15

数据范围及提示 Data Size & Hint

对于30%的数据,1<=n<=10,美貌值<=100

对于50%的数据,1<=n<=50,美貌值<=104

对于100%的数据,1<=n<=200,美貌值不会超过int64的存储范围

 

 

处理每列的前缀和,枚举一个行的上边界,一个下边界,

枚举每列,通过更新最大字段和得到最大矩阵和

 

 1 #include <cstdio>
 2 
 3 inline void read(long long &x)
 4 {
 5     x=0; register char ch=getchar(); register bool __=0; 
 6     for(; ch>'9'||ch<'0'; ch=getchar()) if(ch=='-') __=1;
 7     for(; ch>='0'&&ch<='9'; ch=getchar()) x=x*10+ch-'0';
 8     x=__?((~x)+1):x;
 9 }
10 
11 const int INF(256);
12 const int N(305);
13 long long n,m,val[N][N],tot,ans;
14 
15 int Presist()
16 {
17     read(n);
18     for(int i=1; i<=n; ++i)
19       for(int j=1; j<=n; ++j)
20       {
21           read(val[i][j]);
22 //          if(!val[i][j]) val[i][j]=-INF;
23           val[i][j]+=val[i-1][j];
24       }
25     for(int top=0; top<n; ++top)
26         for(int i=top+1; i<=n; ++i)
27         {
28             tot=0;
29             for(int j=1; j<=n; ++j)
30             {
31                 if(tot<0) tot=val[i][j]-val[top][j];
32                 else tot+=val[i][j]-val[top][j];
33                 if(tot>ans) ans=tot;
34             }
35         }
36     printf("%lld\n",ans);
37     return 0;
38 }
39 
40 int Aptal=Presist();
41 int main(int argc,char*argv[]){;}

 

posted @ 2017-09-28 20:21  Aptal丶  阅读(211)  评论(0编辑  收藏  举报