From e3b5e51b67bd43a5544fd0b154fbd88234100a8c Mon Sep 17 00:00:00 2001 From: jeeminimini Date: Sun, 12 Nov 2023 00:51:33 +0900 Subject: [PATCH] =?UTF-8?q?feat=20:=20=EB=B2=BC=EB=9D=BD=EC=B9=98=EA=B8=B0?= =?UTF-8?q?=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...74\353\235\275\354\271\230\352\270\260.py" | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 "src/main/kotlin/jimin/49week/\353\262\274\353\235\275\354\271\230\352\270\260.py" diff --git "a/src/main/kotlin/jimin/49week/\353\262\274\353\235\275\354\271\230\352\270\260.py" "b/src/main/kotlin/jimin/49week/\353\262\274\353\235\275\354\271\230\352\270\260.py" new file mode 100644 index 00000000..126fee78 --- /dev/null +++ "b/src/main/kotlin/jimin/49week/\353\262\274\353\235\275\354\271\230\352\270\260.py" @@ -0,0 +1,22 @@ +''' +배낭문제 +''' + +import sys +n, t = map(int, sys.stdin.readline().split()) +subjects = [[]] + +for i in range(n): + k, s = map(int, sys.stdin.readline().split()) + subjects.append([k, s]) + +dp = [[0 for _ in range(n + 1)] for _ in range(t + 1)] + +for i in range(1, n + 1): + for j in range(1, t + 1): + if subjects[i][0] > j: + dp[j][i] = dp[j][i - 1] + else: + dp[j][i] = max(dp[j][i - 1], subjects[i][1] + dp[j - subjects[i][0]][i - 1]) + +print(dp[-1][-1]) \ No newline at end of file