Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- using namespace std;
- int map[501][501];
- int dp[501][501];
- int ans=1;
- int n;
- int dy[] = { -1, 1 , 0 ,0 };
- int dx[] = { 0,0,1,-1 };
- int dfs(int y, int x ) {
- for (int i = 0; i < 4; i++) {
- int ny, nx;
- ny = y + dy[i];
- nx = x + dx[i];
- if (ny < 0 || nx < 0 || ny >= n || nx >= n || map[ny][nx] <= map[y][x]) continue;
- if (dp[ny][nx] > 1) {
- if (dp[y][x] < dp[ny][nx] + 1) {
- dp[y][x] = dp[ny][nx] + 1;
- }
- }
- else {
- int cnt = dfs(ny, nx);
- if (cnt > dp[y][x]) {
- dp[y][x] = cnt;
- }
- }
- }
- return dp[y][x] + 1;
- }
- int main() {
- int k;
- scanf_s("%d", &n);
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- scanf_s("%d",&map[i][j]);
- dp[i][j] = 1;
- }
- }
- for (int i = 0; i < n; i++) {
- for (int j = 0; j < n; j++) {
- if (dp[i][j] == 1 ) {
- k = dfs(i, j) -1;
- if (k > ans) {
- ans = k;
- }
- }
- }
- }
- printf_s("%d", ans);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement