모임사진

Untitled

Untitled

14:00~15:30 백준 과제 문제 코드, 알고리즘 리뷰

15:00~17:00 코딩테스트 기출문제 풀이

def solution(alp, cop, problems):
    max_alp = max(max(problem[0] for problem in problems), alp)
    max_cop = max(max(problem[1] for problem in problems), cop)
    
    # DP 배열 초기화: 무한대로 설정하여 최소값 갱신이 용이하도록 함
    dp = [[float('inf')] * (max_cop + 1) for _ in range(max_alp + 1)]
    dp[alp][cop] = 0 # 초기 상태
    
    for cur_alp in range(alp, max_alp + 1):
        for cur_cop in range(cop, max_cop + 1):
            if cur_alp < max_alp:
                dp[cur_alp + 1][cur_cop] = min(dp[cur_alp + 1][cur_cop], dp[cur_alp][cur_cop] + 1)
            if cur_cop < max_cop:
                dp[cur_alp][cur_cop + 1] = min(dp[cur_alp][cur_cop + 1], dp[cur_alp][cur_cop] + 1)
                
            for alp_req, cop_req, alp_rwd, cop_rwd, cost in problems:
                if cur_alp >= alp_req and cur_cop >= cop_req:
                    next_alp = min(max_alp, cur_alp + alp_rwd)
                    next_cop = min(max_cop, cur_cop + cop_rwd)
                    dp[next_alp][next_cop] = min(dp[next_alp][next_cop], dp[cur_alp][cur_cop] + cost)
                    
    return dp[max_alp][max_cop]

# 예시
print(solution(10, 10, [[10,15,2,1,2],[20,20,3,3,4]]))
print(solution(0, 0, [[0,0,2,1,2],[4,5,3,1,2],[4,11,4,0,2],[10,4,0,4,2]]))

모두가 못 푼 첫 문제

다들 집에서 풀어보길

각자 공부 사항 및 소감