This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#define MN 305
#define max(a, b) ((a)>(b)?(a):(b))
const int oo = 1e9;
int n, m, x, c[MN][MN], d[MN][MN], f[MN][MN];
int main() {
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= m; j++) {
scanf("%d", &x);
c[i][j] = x + c[i - 1][j] + c[i][j - 1] - c[i - 1][j - 1];
f[i][j] = -oo;
}
}
for (int j = 1; j <= m; j++) {
for (int i = n; i >= 1; i--) {
d[i][j] = c[i][j];
for (int k = 0; k < i; k++) d[i][j] = max(d[i][j], f[k][i] + c[i][j] - c[k][j]);
for (int k = i + 1; k <= n; k++) f[i][k] = max(f[i][k], d[i][j] - c[k][j] + c[i][j]);
}
}
printf("%d", d[n][m]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |