题解
2023-08-31 19:27:16
发布于:广东
6阅读
0回复
0点赞
#include <iostream>
using namespace std;
const int N = 20;
int a[N][N];
int dp[N][N][N];
int main()
{
int n;
cin >> n;
int x,y,z;
while(cin >> x >> y >> z)
{
if (x == 0 && y == 0 && z == 0) break;
a[x][y] = z;
}
for (int i = 1;i <= 2 * n - 1;i++)
for (int j = 1;j <= i;j++)
for (int k = j;k <= i;k++)
{
dp[i][j][k] = max(max(dp[i - 1][j][k],dp[i - 1][j - 1][k - 1]),max(dp[i - 1][j - 1][k],dp[i - 1][j][k - 1]));
dp[i][j][k] += a[i + 1 - j][j];
if (j != k) dp[i][j][k] += a[i + 1 - k][k];
}
cout << dp[2 * n - 1][n][n] << endl;
return 0;
}
这里空空如也
有帮助,赞一个