From 4547fc7c21742668e8e58f17dc5f3b7a83c6002b Mon Sep 17 00:00:00 2001 From: sh0723 Date: Thu, 17 Sep 2026 14:13:35 +0900 Subject: [PATCH 1/2] =?UTF-8?q?1103=20:=20=EA=B2=8C=EC=9E=84=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week7/BOJ1103/BOJ1103_V1.cpp | 68 ++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/week7/BOJ1103/BOJ1103_V1.cpp diff --git a/src/week7/BOJ1103/BOJ1103_V1.cpp b/src/week7/BOJ1103/BOJ1103_V1.cpp new file mode 100644 index 0000000..702df5e --- /dev/null +++ b/src/week7/BOJ1103/BOJ1103_V1.cpp @@ -0,0 +1,68 @@ +#include +using namespace std; +int N,M; +int dy[4] = {-1,1,0,0}; +int dx[4] = {0,0,1,-1}; +int arr[50][50], visited[50][50]; +int dp[50][50]; +bool cycle; +int dfs(int y, int x) { + if (y >= N || x >= M || y < 0 || x < 0 || arr[y][x] == -1) { + return 0; + } + + if (visited[y][x]) { + cycle = true; + return 0; + } + + if (dp[y][x] != -1) { + return dp[y][x]; + } + + visited[y][x] = 1; + dp[y][x] = 0; + + for (int i=0; i<4; i++) { + int ny = y + dy[i] * arr[y][x]; + int nx = x + dx[i] * arr[y][x]; + + dp[y][x] = max(dp[y][x], 1 + dfs(ny,nx)); + } + + visited[y][x] = 0; + + return dp[y][x]; +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + memset(dp, -1, sizeof(dp)); + + cin >> N >> M; + + for (int i=0; i> temp; + for (int j=0; j Date: Thu, 17 Sep 2026 14:19:06 +0900 Subject: [PATCH 2/2] =?UTF-8?q?1103=20:=20=EA=B2=8C=EC=9E=84=20=EC=B6=9C?= =?UTF-8?q?=EB=A0=A5=20=EC=A0=95=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week7/BOJ1103/BOJ1103_V1.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/week7/BOJ1103/BOJ1103_V1.cpp b/src/week7/BOJ1103/BOJ1103_V1.cpp index 702df5e..2c54bdf 100644 --- a/src/week7/BOJ1103/BOJ1103_V1.cpp +++ b/src/week7/BOJ1103/BOJ1103_V1.cpp @@ -58,11 +58,11 @@ int main() { int ret = dfs(0,0); if (cycle) { - cout << -1; + cout << -1 << '\n'; return 0; } - cout << ret; + cout << ret << '\n'; return 0; -} \ No newline at end of file +}