#include <cstdio>
#include <algorithm>
using namespace std;
int a[301][301];
int sum[301][301];
int dp[301][301];
int r,c;
int recsum(int x1, int x2, int y1, int y2){
return sum[x2][y2] - sum[x1-1][y2] - sum[x2][y1-1] + sum[x1-1][y1-1];
}
int f(int x, int y){
if(x == 0 && y == 0) return 0;
if(x == 0 || y == 0) return -1e9;
if(dp[x][y]) return dp[x][y];
int res = 0;
for (int i=1; i<=x; i++) {
for (int j=1; j<=y; j++) {
res = max(res,f(i-1,j-1) + recsum(i,x,j,y));
}
}
return dp[x][y] = res;
}
int main(){
scanf("%d %d",&r,&c);
for (int i=1; i<=r; i++) {
for (int j=1; j<=c; j++) {
scanf("%d",&a[i][j]);
}
}
for (int i=1; i<=r; i++) {
for (int j=1; j<=c; j++) {
sum[i][j] = sum[i-1][j] + sum[i][j-1] - sum[i-1][j-1] + a[i][j];
}
}
printf("%d",f(r,c));
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
2148 KB |
Output is correct |
2 |
Correct |
0 ms |
2148 KB |
Output is correct |
3 |
Incorrect |
0 ms |
2148 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Halted |
0 ms |
0 KB |
- |