1 #include <cstdio>
2 #include <cstring>
3 #include <algorithm>
4 using namespace std;
5
6 int main()
7 {
8 //freopen( "in.txt","r",stdin );
9 int s1[100][100];
10 int f,v;
11 scanf ( "%d%d",&f,&v );
12 for ( int i = 0; i != f; ++i )
13 for ( int j = 0; j != v; ++j )
14 scanf ( "%d",&s1[i][j] );
15 int s2[100][100];
16 int j2 = 0;
17 for ( int i = 0; i != f; ++i ) // 把需要判断的数挑选出来
18 {
19 int k1 = 0;
20 j2 = 0;
21 for ( int j = i; j <= v-f+i ; ++j ) //主要是 v-f+1 控制条件
22 s2[i][j2++] = s1[i][j];
23 }
24 int max[1000];
25 for ( int i = f - 1,j = 0; j != j2;++j )
26 max[j] = s2[i][j];
27 //for ( int j = 0; j != j2; ++j )
28 // printf ( "%d \n",max[j] );
29 for ( int i = f - 2; i >= 0; --i ) // DP 主要 从最后一行往上判断 每个数sum的max;
30 {
31 int max1;
32 for ( int j = 0; j != j2; ++j )
33 {
34 max1 = -500;
35 int sum;
36 for ( int j1 = j; j1 != j2; ++j1 )
37 {
38 sum = s2[i][j] + max[j1];
39 if ( sum > max1 )
40 max1 = sum;
41 }
42 max[j] = max1;
43 }
44 }
45 sort( max,max+j2 );
46 printf ( "%d\n",max[j2-1] );
47 return 0;
48 }
49