【HDOJ】1081 To The Max

暴力解。

 1 #include <stdio.h>
 2 
 3 #define MAXNUM 105
 4 
 5 int map[MAXNUM][MAXNUM];
 6 
 7 int main() {
 8     int i, j, p, q, tmp, n, max, sum;
 9 
10     while (scanf("%d", &n) != EOF) {
11         for (i=1; i<=n; ++i)
12             for (j=1; j<=n; ++j)
13                 scanf("%d", &map[i][j]);
14         max = 0;
15         for (i=1; i<=n; ++i) {
16             for (j=i; j<=n; ++j) {
17                 sum = 0;
18                 for (p=1; p<=n; ++p) {
19                     tmp = 0;
20                     for (q=i; q<=j; ++q)
21                         tmp += map[p][q];
22                     sum += tmp;
23                     if (sum < 0)
24                         sum = 0;
25                     if (max < sum)
26                         max = sum;
27                 }
28             }
29         }
30         printf("%d\n", max);
31     }
32 
33     return 0;
34 }

 

posted on 2014-04-29 14:29  Bombe  阅读(195)  评论(0编辑  收藏  举报

导航