Skip to content

Commit f6bf3ce

Browse files
authored
[BOJ] 1106 호텔 (G4)
1 parent b59a1f7 commit f6bf3ce

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

김지호/10주차/260303.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# https://www.acmicpc.net/problem/1106
2+
# 호텔, 골드4
3+
4+
import sys
5+
import copy
6+
sys.stdin = open("../../../input.txt",'r')
7+
8+
C, N = map(int,input().split(" ")) # C(도달 최종직원 수), N(도시의 개수)
9+
10+
costs = []
11+
12+
for i in range(N):
13+
cost,customer = map(int,input().split(" "))
14+
costs.append([cost,customer])
15+
16+
costs.sort(key=lambda x:(x[0],-x[1]))
17+
18+
min_cost, min_customer = costs[0]
19+
20+
21+
dp = [0] * (C+1)
22+
23+
for curr in range(1,C+1):
24+
# 최소 대입
25+
if curr <= min_customer:
26+
dp[curr] = min_cost
27+
continue
28+
29+
30+
candidates = []
31+
for cost,customer in costs:
32+
if curr-customer >= 0:
33+
candidates.append(dp[curr-customer] + cost)
34+
35+
if(len(candidates) == 0):
36+
dp[curr] = min_cost
37+
else:
38+
dp[curr] = min(candidates)
39+
40+
# print(f"최소 비용 : {min_cost}")
41+
# print(f"최소 고객수 : {min_customer}")
42+
# print(dp)
43+
print(dp[C])

0 commit comments

Comments
 (0)