链接
https://www.luogu.com.cn/problem/P1006
题目
思路
和方格取数差不多,额外的步骤就是去重:只取当前节点(i,j)的右上或者左下部分。并且最后的答案是dp[m][n-1][m-1][n],只dp到终点的上面和左边一个点
代码
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<algorithm>
#include<queue>
#include<cmath>
#include<map>
#include<string.h>
#include<string>
#include<vector>
#define IOS ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
#define int long long
const int N = 55;
int mp[N][N];
int dp[N][N][N][N];
int dp2[N][N][N][N];
signed main()
{
IOS;
int m, n;
cin >> m >> n;
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
cin >> mp[i][j];
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
for (int k = i+1; k <= m; k++)
for (int l = 1; l < j; l++)//只能选两个区域:右上或者左下:当前ij节点无法到达的区域
{
dp[i][j][k][l] = max(max(dp[i - 1][j][k - 1][l], dp[i - 1][j][k][l - 1]),
max(dp[i][j - 1][k - 1][l], dp[i][j - 1][k][l - 1])) + (mp[i][j] + mp[k][l]);
}
cout <<dp[m-1][n][m][n-1];
return 0;
}
标签:P1006,纸条,NOIP2008,int,include,dp,define
From: https://www.cnblogs.com/zzzsacmblog/p/18682441