Skip to content

Commit 12f193b

Browse files
committed
백준 7579번 앱 v2
문제 링크: https://www.acmicpc.net/problem/7579
1 parent 71acafb commit 12f193b

File tree

4 files changed

+54
-0
lines changed

4 files changed

+54
-0
lines changed

백준 7579번 앱 v2/main.py

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
import sys
2+
3+
4+
def solve():
5+
input = sys.stdin.readline
6+
N, M = map(int, input().strip().split())
7+
mems = [0] + list(map(int, input().strip().split()))
8+
costs = [0] + list(map(int, input().strip().split()))
9+
costs_sum = sum(costs)
10+
dp = [[0 for _ in range(costs_sum + 1)] for _ in range(N + 1)]
11+
answer = 100 * 100
12+
13+
for idx_app in range(1, N + 1):
14+
for cost_crnt in range(0, costs_sum + 1):
15+
if cost_crnt < costs[idx_app]:
16+
dp[idx_app][cost_crnt] = dp[idx_app - 1][cost_crnt]
17+
else:
18+
dp[idx_app][cost_crnt] = max(dp[idx_app - 1][cost_crnt], dp[idx_app -1][cost_crnt - costs[idx_app]] + mems[idx_app])
19+
20+
if dp[idx_app][cost_crnt] >= M:
21+
answer = min(answer, cost_crnt)
22+
23+
print(answer)
24+
25+
26+
if __name__ == '__main__':
27+
solve()

백준 7579번 앱 v2/test1.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
5 60
2+
30 10 20 35 40
3+
3 0 3 5 4
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
6

백준 7579번 앱 v2/test_main.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import sys
2+
from pathlib import Path
3+
from unittest import TestCase
4+
from main import solve
5+
6+
7+
class Test(TestCase):
8+
def my_solve(self, testcase_input):
9+
sys.stdin = open(testcase_input, 'r')
10+
stdout = sys.stdout
11+
sys.stdout = open('stdout.txt', 'w')
12+
solve()
13+
sys.stdout.close()
14+
sys.stdout = stdout
15+
16+
def test_solve(self, testcase_number: str):
17+
self.my_solve('test' + testcase_number + '.txt')
18+
self.assertEqual(
19+
Path('test' + testcase_number + '_answer.txt').read_text().strip(),
20+
Path('stdout.txt').read_text().strip())
21+
22+
def test1_solve(self):
23+
self.test_solve('1')

0 commit comments

Comments
 (0)