From 09acda42713f38449136bb1e1fc8798f78bf7a27 Mon Sep 17 00:00:00 2001 From: LiiNi-coder <97495437+LiiNi-coder@users.noreply.github.com> Date: Fri, 5 Dec 2025 23:40:44 +0900 Subject: [PATCH] =?UTF-8?q?[20251205]=20BOJ=20/=20G5=20/=20=EA=B0=9C?= =?UTF-8?q?=EC=97=85=20/=20=EC=9D=B4=EC=9D=B8=ED=9D=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../05 BOJ \352\260\234\354\227\205.md" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "LiiNi-coder/202512/05 BOJ \352\260\234\354\227\205.md" diff --git "a/LiiNi-coder/202512/05 BOJ \352\260\234\354\227\205.md" "b/LiiNi-coder/202512/05 BOJ \352\260\234\354\227\205.md" new file mode 100644 index 00000000..20ece99b --- /dev/null +++ "b/LiiNi-coder/202512/05 BOJ \352\260\234\354\227\205.md" @@ -0,0 +1,47 @@ +```java +import java.io.*; +import java.util.*; + +public class Main{ + public static void main(String[] args) throws IOException{ + BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + StringTokenizer st = new StringTokenizer(br.readLine()); + int N = Integer.parseInt(st.nextToken()); + int M = Integer.parseInt(st.nextToken()); + st = new StringTokenizer(br.readLine()); + int[] wok = new int[M]; + for(int i = 0; i < M; i++){ + wok[i] = Integer.parseInt(st.nextToken()); + } + + ArrayList cook = new ArrayList<>(); + for(int i = 0; i < M; i++){ + cook.add(wok[i]); + } + for(int i = 0; i < M; i++){ + for(int j = i + 1; j < M; j++){ + cook.add(wok[i] + wok[j]); + } + } + + int INF = 100_000_000; + int[] dp = new int[N + 1]; + Arrays.fill(dp, INF); + dp[0] = 0; + for(int x = 0; x <= N; x++){ + if(dp[x] == INF) + continue; + for(int c : cook){ + int nx = x + c; + if(nx <= N){ + dp[nx] = Math.min(dp[nx], dp[x] + 1); + } + } + } + int answer = dp[N]; + System.out.println((answer >= INF)? -1 : answer); + + } +} + +```