Submission #10101

#TimeUsernameProblemLanguageResultExecution timeMemory
10101gs14004On grid (kriii2_O)C++98
1 / 4
1000 ms2148 KiB
#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 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]; } } for (int i=1; i<=r; i++) { dp[i][1] = sum[i][1]; } for (int i=1; i<=c; i++) { dp[1][i] = sum[1][i]; } for (int i=2; i<=r; i++) { for (int j=2; j<=c; j++) { dp[i][j] = sum[i][j]; for (int k=2; k<=i; k++) { for (int l=2; l<=j; l++) { dp[i][j] = max(dp[i][j],dp[k-1][l-1] + recsum(k,i,l,j)); } } } } printf("%d",dp[r][c]); }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...