Skip to content

Conversation

@cyjadela
Copy link
Contributor

@cyjadela cyjadela commented Sep 1, 2023

문제

#198

해결 과정

import sys
input = sys.stdin.readline

c, n = map(int, input().split())
cost_list = []

for i in range(n):
    cost, people = map(int, input().split())
    cost_list.append([cost, people])

dp = [1e7 for _ in range(c+100)] #최댓값이 100
dp[0] = 0

for cost, people in cost_list:
  for i in range(people, c+100):
    dp[i] = min(dp[i-people]+cost,dp[i])

print(min(dp[c:]))

메모리, 시간

백준 문제일 경우 아래에 입력해주세요

  • 31256KB
  • 52ms

알게된 것

문제를 보고 dp로 어떻게 풀어야겠다는 이제 감이 오는데 실제로 코드로 짜는게 아직 익숙하지 않은 것 같다 ..
책보고 다시 똑바로 공부해야지 !!

@cyjadela cyjadela added the 윤진 label Sep 1, 2023
@cyjadela cyjadela self-assigned this Sep 1, 2023
Copy link
Member

@GIVEN53 GIVEN53 left a comment

Choose a reason for hiding this comment

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

dp 길이를 길게 하는 것도 괜찮네요!

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가 어려워서 여러번 풀면서 연습했었어요 ~ 홧팅 !

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