Submission #10097

#TimeUsernameProblemLanguageResultExecution timeMemory
10097sutekineOn grid (kriii2_O)C++98
1 / 4
1000 ms2216 KiB
#include <cstdio> #include <algorithm> #define oo 987654321 int R, C, A[311][311], S[311][311], DT[310][310]; int f(int a, int b) { int ans = -oo; if( a == R+1 && b == C+1 ) return 0; if( a == R+1 || b == C+1 ) return -oo; if( DT[a][b] == 0 ) { for(int i = a ; i <= R ; i++ ) for( int j = b ; j <= C ; j++ ) ans = std::max( ans, S[i][j] - S[a-1][j] - S[i][b-1] + S[a-1][b-1] + f(i+1, j+1) ); DT[a][b] = ans; } return DT[a][b]; } 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++ ) if( i == 1 && j == 1 ) S[i][j] = A[i][j]; else S[i][j] = S[i-1][j] + S[i][j-1] - S[i-1][j-1] + A[i][j]; printf("%d", f(1,1)); return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...