#include <stdio.h>
#include <algorithm>
using namespace std;
int n, m;
int a[301][301];
int s[301][301];
int d[301][301];
int w[301][301][301];
int main ()
{
scanf ("%d%d", &n, &m);
for (int i=1; i<=n; i++) for (int j=1; j<=m; j++) {
scanf ("%d", &a[i][j]);
s[i][j] = s[i-1][j] + s[i][j-1] - s[i-1][j-1] + a[i][j];
}
for (int i=1; i<=n; i++) {
for (int j=1; j<=m; j++) {
d[i][j] = s[i][j];
for (int a=1; a<i; a++) {
if (d[i][j] < w[a][i][j] + s[i][j] - s[a][j])
d[i][j] = w[a][i][j] + s[i][j] - s[a][j];
}
for (int a=1; a<i; a++)
w[a][i][j+1] = max (w[a][i][j], d[a][j] + s[a][j] - s[i][j]);
}
}
printf ("%d\n", d[n][m]);
return 0;
}
/*
2 2
1 -1
-1 1
5 5
4 -2 3 -4 2
-2 1 1 4 -2
-3 1 -1 2 5
2 -4 2 3 5
1 -4 4 -1 -2
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
108676 KB |
Output is correct |
2 |
Correct |
0 ms |
108676 KB |
Output is correct |
3 |
Correct |
0 ms |
108676 KB |
Output is correct |
4 |
Correct |
0 ms |
108676 KB |
Output is correct |
5 |
Correct |
0 ms |
108676 KB |
Output is correct |
6 |
Correct |
0 ms |
108676 KB |
Output is correct |
7 |
Incorrect |
0 ms |
108676 KB |
Output isn't correct |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |