dp1 最大子矩阵

///比赛想了好长时间的最大子矩阵...出来看看题解才懂,自己真蠢= =

 

 

 

 1 #include <algorithm>
 2 #include <stack>
 3 #include <istream>
 4 #include <stdio.h>
 5 #include <map>
 6 #include <math.h>
 7 #include <vector>
 8 #include <iostream>
 9 #include <queue>
10 #include <string.h>
11 #include <set>
12 #include <cstdio>
13 #define FR(i,n) for(int i=0;i<n;i++)
14 #define MAX 2005
15 #define mkp pair <int,int>
16 using namespace std;
17 const int maxn = 2e2 + 3;
18 typedef long long ll;
19 
20 void read(int &x) {
21 char ch; bool flag = 0;
22 for (ch = getchar(); !isdigit(ch) && ((flag |= (ch == '-')) || 1); ch = getchar());
23 for (x = 0; isdigit(ch); x = (x << 1) + (x << 3) + ch - 48, ch = getchar());
24 x *= 1 - 2 * flag;
25 }
26 
27 int sum[maxn][maxn];
28 int arr[maxn][maxn];
29 int main() {
30 int n;
31 while(~scanf("%d",&n))
32 {
33 memset(sum,0,sizeof(sum));
34 for(int i=1;i<=n;i++)
35 {
36 for(int j=1;j<=n;j++)
37 {
38 scanf("%d",&arr[i][j]);
39 sum[i][j]=arr[i][j]+sum[i][j-1];
40 }
41 }
42 int ans=-0x3f;
43 ///cout<<ans<<endl;
44 for(int i=1;i<=n;i++)
45 {
46 for(int j=i;j<=n;j++)
47 {
48 int sub=0;
49 for(int m=1;m<=n;m++)
50 {
51 if(sub<0)sub=0;
52 sub+=sum[m][j]-sum[m][i-1];
53 ans=max(sub,ans);
54 }
55 }
56 }
57 cout<<ans<<endl;
58 }
59 return 0;
60 }

 

posted @ 2018-06-10 23:05  Xzavieru  阅读(99)  评论(0编辑  收藏  举报