参考代码:
#include<bits/stdc++.h> using namespace std; const int SIZE = 52; int Map[SIZE][SIZE]; int Dp[SIZE][SIZE][SIZE][SIZE]; int Maph, Mapw; int DFS(int posxst, int posyst, int posxnd, int posynd) { if (posxst > Maph || posyst > Mapw || posxnd > Maph || posynd > Mapw) return 0; if (Dp[posxst][posyst][posxnd][posynd] != -1) return Dp[posxst][posyst][posxnd][posynd]; int res = Map[posxst][posyst] + Map[posxnd][posynd]; if (posxst == posxnd && posyst == posynd) res -= Map[posxnd][posynd]; res += max(max(DFS(posxst, posyst + 1, posxnd + 1, posynd), DFS(posxst, posyst + 1, posxnd, posynd + 1)), max(DFS(posxst + 1, posyst, posxnd + 1, posynd), DFS(posxst + 1, posyst, posxnd, posynd + 1))); return Dp[posxst][posyst][posxnd][posynd] = res; } int main() { scanf("%d%d", &Maph, &Mapw); for (int posx = 1; posx <= Maph; posx++) for (int posy = 1; posy <= Mapw; posy++) scanf("%d", &Map[posx][posy]); memset(Dp, -1, sizeof Dp); printf("%d\n", DFS(1, 1, 1, 1)); }
0.0分
1 人评分
C语言程序设计教程(第三版)课后习题6.1 (C语言代码)浏览:641 |
杨辉三角 (C语言代码)浏览:504 |
C二级辅导-阶乘数列 (C语言代码)浏览:583 |
输出九九乘法表 (C语言代码)浏览:1172 |
C语言程序设计教程(第三版)课后习题12.2 (C语言代码)浏览:839 |
C语言程序设计教程(第三版)课后习题6.7 (C语言代码)浏览:725 |
简单的事情 (C语言代码)浏览:679 |
最好的,浏览:601 |
矩阵转置 (C语言代码)浏览:855 |
纪念品分组 (C++代码)浏览:878 |