标签:acm codeforces
const int MAXN = 1005; int lu[MAXN][MAXN], ld[MAXN][MAXN]; int ru[MAXN][MAXN], rd[MAXN][MAXN]; int ipt[MAXN][MAXN]; int n, m; int main() { // freopen("in.txt", "r", stdin); while (~RII(n, m)) { CLR(ipt, -1); FE(i, 1, n) FE(j, 1, m) RI(ipt[i][j]); lu[1][1] = ipt[1][1]; ru[1][m] = ipt[1][m]; ld[n][1] = ipt[n][1]; rd[n][m] = ipt[n][m]; FE(i, 1, n) FE(j, 1, m) { lu[i][j + 1] = max(lu[i][j + 1], lu[i][j] + ipt[i][j + 1]); lu[i + 1][j] = max(lu[i + 1][j], lu[i][j] + ipt[i + 1][j]); } FE(i, 1, n) FED(j, m, 1) { ru[i][j - 1] = max(ru[i][j - 1], ru[i][j] + ipt[i][j - 1]); ru[i + 1][j] = max(ru[i + 1][j], ru[i][j] + ipt[i + 1][j]); } FED(i, n, 1) FE(j, 1, m) { ld[i][j + 1] = max(ld[i][j + 1], ld[i][j] + ipt[i][j + 1]); ld[i - 1][j] = max(ld[i - 1][j], ld[i][j] + ipt[i - 1][j]); } FED(i, n, 1) FED(j, m, 1) { rd[i][j - 1] = max(rd[i][j - 1], rd[i][j] + ipt[i][j - 1]); rd[i - 1][j] = max(rd[i - 1][j], rd[i][j] + ipt[i - 1][j]); } int ans = 0; FE(i, 1, n) FE(j, 1, m) { if (i - 1 >= 1 && j - 1 >= 1 && i + 1 <= n && j + 1 <= m) { ans = max(ans, lu[i - 1][j] + ld[i][j - 1] + rd[i + 1][j] + ru[i][j + 1]); } if (j - 1 >= 1 && i + 1 <= n && j + 1 <= m && i - 1 >= 1) { ans = max(ans, lu[i][j - 1] + ld[i + 1][j] + rd[i][j + 1] + ru[i - 1][j]); } } WI(ans); } return 0; }
Codeforces Round #245 (Div. 1)——Working out,布布扣,bubuko.com
Codeforces Round #245 (Div. 1)——Working out
标签:acm codeforces
原文地址:http://blog.csdn.net/wty__/article/details/25622269