From c50d10c96b0e58e56499c0bf99bc06e5e99dd577 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=B5=9C=EB=AC=B8=ED=98=95?= <74577714+alirz-pixel@users.noreply.github.com> Date: Thu, 8 Jan 2026 22:35:57 +0900 Subject: [PATCH] =?UTF-8?q?260108=20:=20[BOJ=201937]=20=EC=9A=95=EC=8B=AC?= =?UTF-8?q?=EC=9F=81=EC=9D=B4=20=ED=8C=90=EB=8B=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- _munhyeong/1937.cpp | 66 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) create mode 100644 _munhyeong/1937.cpp diff --git a/_munhyeong/1937.cpp b/_munhyeong/1937.cpp new file mode 100644 index 00000000..33efdf21 --- /dev/null +++ b/_munhyeong/1937.cpp @@ -0,0 +1,66 @@ +#include +#include + +using namespace std; + +int dy[4] = { 1, -1, 0, 0 }; +int dx[4] = { 0, 0, 1, -1 }; +int DFS(vector>& board, vector> &dp, int y, int x) { + if (dp[y][x]) + return dp[y][x]; + dp[y][x] = 1; // 방문체크 + + int maxV = 1; + for (int dir = 0; dir < 4; dir++) { + int ny = y + dy[dir]; + int nx = x + dx[dir]; + + if (ny < 0 || nx < 0 || ny >= board.size() || nx >= board[0].size()) + continue; + if (board[y][x] >= board[ny][nx]) + continue; + + maxV = max(maxV, DFS(board, dp, ny, nx) + 1); + } + + return dp[y][x] = maxV; +} + +void print(vector> dp) { + int N = dp.size(); + for (int y = 0; y < N; y++) { + for (int x = 0; x < N; x++) { + cout << dp[y][x] << " " ; + } + cout << endl; + } +} + +int main() { + cin.tie(0); + ios_base::sync_with_stdio(false); + + int N; + cin >> N; + + vector> board(N, vector(N)); + for (int i = 0; i < N; i++) { + for (int j = 0; j < N; j++) { + cin >> board[i][j]; + } + } + + vector> dp(N, vector(N)); + int answer = 0; + for (int y = 0; y < N; y++) { + for (int x = 0; x < N; x++) { + answer = max(answer, DFS(board, dp, y, x)); + // print(dp); + // cout << "\n"; + } + } + + + + cout << answer; +}