From 94b743975b5202dc01ba8576fe68cc64575eec0f Mon Sep 17 00:00:00 2001 From: keunho Date: Tue, 1 Oct 2024 22:56:29 +0900 Subject: [PATCH] =?UTF-8?q?2024-10-01=20=ED=8F=89=EB=B2=94=ED=95=9C=20?= =?UTF-8?q?=EB=B0=B0=EB=82=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- kokeunho/README.md | 3 ++- .../2-kokeunho.py" | 23 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 "kokeunho/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/2-kokeunho.py" diff --git a/kokeunho/README.md b/kokeunho/README.md index 0aa548a..20d71ca 100644 --- a/kokeunho/README.md +++ b/kokeunho/README.md @@ -2,5 +2,6 @@ | 차시 | 날짜 | 문제유형 | 링크 | 풀이 | |:----:|:---------:|:----:|:-----:|:----:| -| 1차시 | 2024.09.28 | 구현 | [킹](https://www.acmicpc.net/problem/1063) | [#43](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/1) | +| 1차시 | 2024.09.28 | 구현 | [킹](https://www.acmicpc.net/problem/1063) | [#1](https://github.com/AlgoLeadMe/AlgoLeadMe-12/pull/1) | +| 2차시 | 2024.10.01 | 다이나믹 프로그래밍 | [평범한 배낭](https://www.acmicpc.net/problem/12865) | [#5] (https://github.com/AlgoLeadMe/AlgoLeadMe-12/pulls/4) | --- diff --git "a/kokeunho/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/2-kokeunho.py" "b/kokeunho/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/2-kokeunho.py" new file mode 100644 index 0000000..ba673fa --- /dev/null +++ "b/kokeunho/\353\213\244\354\235\264\353\202\230\353\257\271 \355\224\204\353\241\234\352\267\270\353\236\230\353\260\215/2-kokeunho.py" @@ -0,0 +1,23 @@ +N, K = map(int, input().split()) +items = [] + +for _ in range(N): + W, V = map(int, input().split()) + items.append((W, V)) + +dp = [[0] * (K+1) for _ in range(N+1)] + +for i in range(1, N+1): + weight, value = items[i-1] + for j in range(1, K+1): + if j >= weight: + dp[i][j] = max(dp[i-1][j], dp[i-1][j-weight] + value) + else: + dp[i][j] = dp[i-1][j] + +print(dp[N][K]) + + + + +