-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path洛谷(1006).cpp
47 lines (40 loc) · 1.56 KB
/
洛谷(1006).cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#include <cstdio>
#include <algorithm>
#define MY_INF -2100000000
using namespace std;
int max_num(int a, int b, int c, int d) {
return max(max(a, b), max(c, d));
}
int map[51][51] = {0};
int dp[51][51][51][51] = {0};
int main() {
int m, n = 0;
scanf("%d%d", &m, &n);
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
scanf("%d", &map[i][j]);
dp[1][1][1][1] = map[1][1];
for (int i = 1; i <= m; i++)
for (int j = 1; j <= n; j++)
for (int k = 1; k <= m; k++)
for (int l = 1; l <= n; l++) {
if (i == 1 && k == 1 && j == 1 && l == 1)
continue;
if (i == m && k == m && j == n && l == n) {
dp[i][j][k][l] = max_num(dp[i][j - 1][k][l - 1],
dp[i - 1][j][k - 1][l],
dp[i][j - 1][k - 1][l],
dp[i - 1][j][k][l - 1]);
continue;
}
if (i == k && j == l)
dp[i][j][k][l] = MY_INF;
else
dp[i][j][k][l] = max_num(dp[i][j - 1][k][l - 1],
dp[i - 1][j][k - 1][l],
dp[i][j - 1][k - 1][l],
dp[i - 1][j][k][l - 1]) + map[i][j] + map[k][l];
}
printf("%d", dp[m][n][m][n]);
return 0;
}