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>
#include<algorithm>
using namespace std;
int D[2][310][310], n, m, S[310][310], pv, D2[2][310];
int main()
{
int i, j, k;
scanf("%d%d", &n,&m);
for (i = 1; i <= n; i++){
for (j = 1; j <= m; j++){
scanf("%d", &S[i][j]);
S[i][j] += S[i][j - 1];
}
}
for (i = 1; i <= m; i++){
D2[0][i] = D[0][i][i] = S[1][i];
for (j = 1; j < i; j++)D[0][i][j] = -1999999999;
}
for (i = 2; i <= n; i++){
for (j = 1; j <= m; j++)D2[!pv][j] = -1999999999;
D2[pv][0] = -1999999999;
for (j = 1; j <= m; j++){
for (k = 1; k <= j; k++){
D[!pv][j][k] = max(D[pv][j][k], D2[pv][j - k]) + S[i][j] - S[i][j - k];
D2[!pv][j] = max(D2[!pv][j], D[!pv][j][k]);
}
}
pv = !pv;
}
printf("%d\n", D2[pv][m]);
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |