File tree Expand file tree Collapse file tree 1 file changed +43
-0
lines changed
Expand file tree Collapse file tree 1 file changed +43
-0
lines changed Original file line number Diff line number Diff line change 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 ])
You can’t perform that action at this time.
0 commit comments