#include <iostream> #include <algorithm> #include <queue> #include <string.h> using namespace std; int N; int map[510][510]; int dp[510][510]; int Max; int dx[4] = {-1, 1, 0, 0}; int dy[4] = {0, 0, -1, 1}; int safe(int x, int y) { if(x >= 0 && y >= 0 && x < N && y < N) { return 1; } else { return 0; } } int DFS(int x, int y) { if(dp[x][y] != 0) { return dp[x][y]; } dp[x][y] = 1; for(int i = 0; i < 4; i++) { int xpos = x+dx[i]; int ypos = y+dy[i]; if(safe(xpos, ypos) == 1) { if(map[x][y] < map[xpos][ypos]) { dp[x][y] = max(dp[x][y], DFS(xpos, ypos) + 1); } } } return dp[x][y]; } int main(void) { // freopen("B1937_input.txt", "r", stdin); cin >> N; for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { cin >> map[i][j]; } } for(int i = 0; i < N; i++) { for(int j = 0; j < N; j++) { Max = max(Max, DFS(i, j)); } } cout << Max; return 0; } | cs |
'Baekjoon > DP' 카테고리의 다른 글
[백준 2186] 문자판 (DFS, DP) (C/C++) (★★★) (0) | 2020.03.17 |
---|---|
[백준 1520] 내리막 길 (DFS, DP) (C/C++) (★★) (0) | 2020.03.17 |
[백준 1309] 동물원 (DP) (C/C++) (★★) (0) | 2020.03.16 |
[백준 1965] 상자 넣기 (DP) (C/C++) (0) | 2020.03.16 |
[백준 9252] LCS 2 (DP) (C/C++) (★★★) (0) | 2020.03.16 |