From adfb1ecd39835d9828857e4168055c56563060a0 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Thu, 17 Sep 2026 17:23:29 +0900 Subject: [PATCH 1/2] =?UTF-8?q?2240=20:=20=EC=9E=90=EB=91=90=EB=82=98?= =?UTF-8?q?=EB=AC=B4=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week7/BOJ2240/BOJ2240_V1.cpp | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 src/week7/BOJ2240/BOJ2240_V1.cpp diff --git a/src/week7/BOJ2240/BOJ2240_V1.cpp b/src/week7/BOJ2240/BOJ2240_V1.cpp new file mode 100644 index 0000000..3a2f9fc --- /dev/null +++ b/src/week7/BOJ2240/BOJ2240_V1.cpp @@ -0,0 +1,35 @@ +#include +using namespace std; +int T,W, dp[1000][2][31]; +int arr[1000]; +int solve(int idx, int tree, int cnt) { + if (cnt < 0) return -1e9; + + if (idx == T) return 0; + + int &ret = dp[idx][tree][cnt]; + + if (ret != -1) return ret; + + return ret = max(solve(idx+1, tree, cnt), solve(idx+1, tree^1, cnt-1)) + (tree == arr[idx]-1); +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + cin >> T >> W; + + memset(dp, -1, sizeof(dp)); + + for (int i=0; i> arr[i]; + } + + int ret = max(solve(0,0,W),solve(0, 1, W-1)); + + cout << ret; + + return 0; +} \ No newline at end of file From 3f5c29d0eec70b1f78cfabf9f03dda8f61ae3239 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Thu, 17 Sep 2026 17:28:07 +0900 Subject: [PATCH 2/2] =?UTF-8?q?2240=20:=20=EC=9E=90=EB=91=90=EB=82=98?= =?UTF-8?q?=EB=AC=B4=20=EC=B6=9C=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/BOJ2240/BOJ2240_V1.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/week7/BOJ2240/BOJ2240_V1.cpp b/src/week7/BOJ2240/BOJ2240_V1.cpp index 3a2f9fc..a9b7ab0 100644 --- a/src/week7/BOJ2240/BOJ2240_V1.cpp +++ b/src/week7/BOJ2240/BOJ2240_V1.cpp @@ -29,7 +29,7 @@ int main() { int ret = max(solve(0,0,W),solve(0, 1, W-1)); - cout << ret; + cout << ret << '\n'; return 0; -} \ No newline at end of file +}