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