#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;
int sum[302][302], num[300][300];
int best[300][300];
int main()
{
int R, C;
cin >> R >> C;
for (int i=0; i<R; i++) for (int j=0; j<C; j++) cin >> num[i][j];
for (int i=0; i<R; i++) for (int j=0; j<C; j++)
sum[i+1][j+1] = sum[i+1][j] + sum[i][j+1] - sum[i][j] + num[i][j];
for (int i=0; i<C; i++) best[0][i] = sum[1][i+1];
for (int i=1; i<R; i++) {
best[i][0] = sum[i+1][1];
for (int j=1; j<C; j++) best[i][j] = -999999999;
for (int j=-1; j<i; j++) {
int last = -999999999;
for (int k=1; k<C; k++) {
int nxt1 = last + sum[i+1][k+1] - sum[j+1][k+1] - sum[i+1][k] + sum[j+1][k];
best[i][k] = max(best[i][k], nxt1);
last = max(last, nxt1);
int nxt2 = sum[j+1][k] + sum[i+1][k+1] - sum[j+1][k+1] - sum[i+1][k] + sum[j+1][k];
best[i][k] = max(best[i][k], nxt2);
last = max(last, nxt2);
}
}
// for (int j=0; j<C; j++) printf("%d ", best[i][j]); printf("\n");
}
cout << best[R-1][C-1] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2732 KB |
Output is correct |
2 |
Incorrect |
0 ms |
2732 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |