ok啊干翻cpu了好吧
2023-10-06 09:16:51
发布于:台湾
5阅读
0回复
0点赞
#include <iostream>
#include <algorithm>
using namespace std;
const int MAXN = 55;
int m, n, a[MAXN][MAXN], dp[MAXN][MAXN][MAXN];
int main() {
cin >> m >> n;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
cin >> a[i][j];
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= m; k++) {
int l = i + j - k;
if (l >= 1 && l <= n) {
int temp = max(max(dp[i - 1][j][k - 1], dp[i - 1][j][k]), max(dp[i][j - 1][k - 1], dp[i][j - 1][k]));
dp[i][j][k] = temp + a[i][j];
if (i != k) dp[i][j][k] += a[k][l];
}
}
cout << dp[m][n][m] << endl;
return 0;
}
这里空空如也
有帮助,赞一个