-
2022 KAKAO TECH INTERNSHIP 코딩 테스트 공부코딩 테스트/Level 3 2022. 11. 20. 23:31반응형
https://school.programmers.co.kr/learn/courses/30/lessons/118668
https://tech.kakao.com/2022/07/13/2022-coding-test-summer-internship/
def solution(alp, cop, problems): max_alp = max_cop = 0 for each_alp, each_cop, *_ in problems: max_alp = max(each_alp, max_alp) max_cop = max(each_cop, max_cop) dp = [[float('inf') for _ in range(max_cop + 1)] for _ in range(max_alp + 1)] alp, cop = min(alp, max_alp), min(cop, max_cop) dp[alp][cop] = 0 for i in range(alp, max_alp + 1): for j in range(cop, max_cop + 1): if i < max_alp: dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + 1) if j < max_cop: dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + 1) for alp_req, cop_req, alp_rwd, cop_rwd, cost in problems: if i >= alp_req and j >= cop_req: next_alp, next_cop = min(max_alp, i + alp_rwd), min(max_cop, j + cop_rwd) dp[next_alp][next_cop] = min(dp[next_alp][next_cop], dp[i][j] + cost) return dp[-1][-1]
반응형