冬笙夏洛_ @ 2021-04-06 15:58:18
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int dp[105][105];
int flag[105][105];
int row[4] = { -1,0,1,0 };
int col[4] = { 0,1,0,-1 };
ll max(ll a, ll b) {
return a > b ? a : b;
}
int main() {
int n,m;
cin >> n >> m;
for (int i = 0;i <= m + 1;i++)
dp[0][i] = dp[n + 1][i] = 9999999;
for (int i = 0;i <= n + 1;i++)
dp[i][0] = dp[i][m + 1] = 9999999;
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++) {
cin >> dp[i][j];
flag[i][j] = 1;
}
for(int i=1;i<=n;i++)
for (int j = 1;j <= m;j++) {
for (int k = 0;k < 4;k++)
if (dp[i][j] > dp[i + row[k]][j + col[k]])
flag[i][j] = max(flag[i][j],flag[i+row[k]][j+col[k]]+dp[i][j]- dp[i + row[k]][j + col[k]]);
}
ll max1=flag[1][1];
for (int i = 1;i <= n;i++)
for (int j = 1;j <= m;j++)
max1 = max(max1, flag[i][j]);
cout << max1 << endl;
cout << endl;
return 0;
}