#include <stdio.h>
int N, M;
int A[301][301], S[301][301], D[301][301], V[301][301];
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", A[i]+j), S[i][j] = A[i][j]+S[i-1][j]+S[i][j-1]-S[i-1][j-1];
for (i=0;i<=N;i++) for (j=0;j<=N;j++) V[i][j] = -1e9;
for (j=1;j<=M;j++) for (i=1;i<=N;i++){
D[i][j] = S[i][j];
for (int a=0;a<i;a++){
if (V[a][i] > -1e9 && D[i][j] < V[a][i]+S[i][j]-S[a][j])
D[i][j] = V[a][i]+S[i][j]-S[a][j];
}
for (int a=i+1;a<=N;a++){
if (V[i][a] < D[i][j]-S[a][j]+S[i][j])
V[i][a] = D[i][j]-S[a][j]+S[i][j];
}
}
printf("%d\n", D[N][M]);
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2504 KB |
Output is correct |
2 |
Correct |
0 ms |
2504 KB |
Output is correct |
3 |
Correct |
0 ms |
2504 KB |
Output is correct |
4 |
Incorrect |
0 ms |
2504 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |