Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BOJ] 1106 : 호텔 (23.09.01) #198

Merged
merged 1 commit into from
Sep 6, 2023
Merged

[BOJ] 1106 : 호텔 (23.09.01) #198

merged 1 commit into from
Sep 6, 2023

Conversation

GIVEN53
Copy link
Member

@GIVEN53 GIVEN53 commented Sep 1, 2023

문제

#197

해결 과정

from sys import stdin

c, n = map(int, stdin.readline().split())
city = [list(map(int, stdin.readline().split())) for _ in range(n)]
dp = [1e9] * (c + 1) # index는 고객 수, value는 해당 고객 수를 얻을 수 있는 최소 비용
dp[0] = 0

for i in range(1, c + 1):
    for cost, customer in city:
        if i <= customer: # i 고객 수 이상을 모두 만들 수 있으면
            dp[i] = min(dp[i], cost) # 현재 도시의 비용과 최솟값 갱신
        else: # 만들 수 없으면
            dp[i] = min(dp[i], dp[i - customer] + cost) # i - customer의 비용 + 현재 도시의 비용과 최솟값 갱신

print(dp[-1])

메모리, 시간

  • 31256KB
  • 52ms

@GIVEN53 GIVEN53 added the 기범 label Sep 1, 2023
@GIVEN53 GIVEN53 self-assigned this Sep 1, 2023
Copy link
Contributor

@cyjadela cyjadela left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

아주 깔끔하게 잘푸셨군요 !!! 👍🏻

@cyjadela cyjadela mentioned this pull request Sep 1, 2023
Copy link
Contributor

@13wjdgk 13wjdgk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

dp로 쉽게 풀었군요 !

@GIVEN53 GIVEN53 merged commit 89268c3 into main Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants