Created
June 6, 2021 20:57
-
-
Save vishnupsatish/a644d9f0f2849b137680d461f7dc9f89 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#define el "\n" | |
#define ll long long | |
using namespace std; | |
const int MM = 1502; | |
int dp[MM][MM], n; | |
ll a[MM][MM]; | |
int f(int r, int c) { | |
if (dp[r][c] != 0) return dp[r][c]; | |
int re = 0; | |
if (a[r - 1][c] != 0 && a[r - 1][c] > a[r][c]) re = max(re, 1 + f(r - 1, c)); | |
if (a[r + 1][c] != 0 && a[r + 1][c] > a[r][c]) re = max(re, 1 + f(r + 1, c)); | |
if (a[r][c - 1] != 0 && a[r][c - 1] > a[r][c]) re = max(re, 1 + f(r, c - 1)); | |
if (a[r][c + 1] != 0 && a[r][c + 1] > a[r][c]) re = max(re, 1 + f(r, c + 1)); | |
return dp[r][c] = re; | |
} | |
int main() { | |
cin.tie(0); ios::sync_with_stdio(0); | |
cin >> n; | |
int ans = 0; | |
for (int i = 1; i <= n; i++) { | |
for (int j = 1; j <= n; j++) { | |
cin >> a[i][j]; | |
} | |
} | |
for (int i = 1; i <= n; i++) { | |
for (int j = 1; j <= n; j++) { | |
ans = max(ans, f(i, j)); | |
} | |
} | |
cout << ans << el; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment