From cad6477128f9046936de800c8f1d72ebf67d8ffd Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 29 Jun 2026 16:11:08 +0900 Subject: [PATCH] =?UTF-8?q?15684=20:=20=EC=82=AC=EB=8B=A4=EB=A6=AC=20?= =?UTF-8?q?=EC=A1=B0=EC=9E=91=20resolve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week3/BOJ15684/BOJ15684_V2.cpp | 54 ++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 src/week3/BOJ15684/BOJ15684_V2.cpp diff --git a/src/week3/BOJ15684/BOJ15684_V2.cpp b/src/week3/BOJ15684/BOJ15684_V2.cpp new file mode 100644 index 0000000..dbebd25 --- /dev/null +++ b/src/week3/BOJ15684/BOJ15684_V2.cpp @@ -0,0 +1,54 @@ +#include +using namespace std; +int visited[31][11]; +int N,M,H; +int ret = 4; +bool check() { + for (int i=1; i<=N; i++) { + int start = i; + for (int j=1; j<=H; j++) { + if (visited[j][start]) start++; + else if (visited[j][start-1]) start--; + } + if (start != i) return false; + } + return true; +} +void solve(int here, int cnt) { + if (cnt > 3 || cnt >= ret) return; + + if (check()) { + ret = cnt; + return; + } + + for (int i=here; i<=H; i++) { + for (int j=1; j> N >> M >> H; + + for (int i=0; i> a >> b; + visited[a][b] = 1; + } + + solve(1,0); + if (ret == 4) cout << -1 << '\n'; + else cout << ret << '\n'; + + + return 0; +} \ No newline at end of file