From 990bb1f047d4316deb11fca10d625b88a8dc72c2 Mon Sep 17 00:00:00 2001 From: sh0723 Date: Mon, 28 Sep 2026 19:00:10 +0900 Subject: [PATCH] =?UTF-8?q?2294=20:=20=EB=8F=99=EC=A0=84=202=20solve?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/week7/BOJ2294/BOJ2294_V1.cpp | 39 ++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 src/week7/BOJ2294/BOJ2294_V1.cpp diff --git a/src/week7/BOJ2294/BOJ2294_V1.cpp b/src/week7/BOJ2294/BOJ2294_V1.cpp new file mode 100644 index 0000000..5ac0149 --- /dev/null +++ b/src/week7/BOJ2294/BOJ2294_V1.cpp @@ -0,0 +1,39 @@ +#include +using namespace std; +int N,k; +int dp[100001]; +vector inp(100); +int solve(int n) { + if (dp[n] != -1) return dp[n]; + + + int min_val = k+1; + for (int i = 0; i < N; i++) { + int coin_val = inp[i]; + if (coin_val <= n) { + min_val = min(min_val, solve(n - coin_val) + 1); + } + } + return dp[n] = min_val; + +} +int main() { + + ios_base::sync_with_stdio(false); + cin.tie(nullptr); + cout.tie(nullptr); + + + cin >> N >> k; + for (int i=0; i> inp[i]; + } + + fill(dp, dp + k + 1, -1); + dp[0] = 0; + + int ret = solve(k); + cout << (ret > k ? -1 : ret) << '\n'; + + return 0; +} \ No newline at end of file