From d5417e79ebb59501a740b92c246600b0998cb355 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Tue, 15 Sep 2026 15:29:01 +0900 Subject: [PATCH 1/2] =?UTF-8?q?14002=20:=20=EA=B0=80=EC=9E=A5=20=EA=B8=B4?= =?UTF-8?q?=20=EC=A6=9D=EA=B0=80=ED=95=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=97=B4=204=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week6/BOJ14002/BOJ14002_V1.cpp | 49 ++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 src/week6/BOJ14002/BOJ14002_V1.cpp diff --git a/src/week6/BOJ14002/BOJ14002_V1.cpp b/src/week6/BOJ14002/BOJ14002_V1.cpp new file mode 100644 index 0000000..1d3ca1f --- /dev/null +++ b/src/week6/BOJ14002/BOJ14002_V1.cpp @@ -0,0 +1,49 @@ +#include +using namespace std; +int arr[1000], cnt[1000], ret=1, idx; +int _prev[1000]; +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + fill(cnt, cnt+1000, 1); + fill(_prev, _prev+1000, -1); + int N; + cin >> N; + + for (int i=0; i> arr[i]; + } + + + for (int i=0; i arr[j] && cnt[j] + 1 > cnt[i]) { + cnt[i] = cnt[j] + 1; + _prev[i] = j; + if (ret < cnt[i]) { + ret = cnt[i]; + idx = i; + } + } + } + } + cout << ret << '\n'; + + stack stk; + while(true) { + if (idx == -1) break; + stk.push(arr[idx]); + idx = _prev[idx]; + } + + while(stk.size()) { + cout << stk.top() << ' '; + stk.pop(); + } + + + return 0; +} \ No newline at end of file From d59c577acc680e11468ecd5f3fd8f4a35c5e3b01 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Tue, 15 Sep 2026 15:34:40 +0900 Subject: [PATCH 2/2] =?UTF-8?q?14002=20:=20=EA=B0=80=EC=9E=A5=20=EA=B8=B4?= =?UTF-8?q?=20=EC=A6=9D=EA=B0=80=ED=95=98=EB=8A=94=20=EB=B6=80=EB=B6=84=20?= =?UTF-8?q?=EC=88=98=EC=97=B4=204=20=EC=B6=9C=EB=A0=A5=20=EC=A0=95?= =?UTF-8?q?=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week6/BOJ14002/BOJ14002_V1.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/week6/BOJ14002/BOJ14002_V1.cpp b/src/week6/BOJ14002/BOJ14002_V1.cpp index 1d3ca1f..9f04da1 100644 --- a/src/week6/BOJ14002/BOJ14002_V1.cpp +++ b/src/week6/BOJ14002/BOJ14002_V1.cpp @@ -39,11 +39,15 @@ int main() { idx = _prev[idx]; } + bool first = true; while(stk.size()) { - cout << stk.top() << ' '; + if (!first) cout << ' '; + cout << stk.top(); + first = false; stk.pop(); } + cout << '\n'; return 0; -} \ No newline at end of file +}