1335. Minimum Difficulty of a Job Schedule 풀이 python

2023. 12. 30. 23:36·코딩테스트/Python

https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/

 

Minimum Difficulty of a Job Schedule - LeetCode

Can you solve this real interview question? Minimum Difficulty of a Job Schedule - You want to schedule a list of jobs in d days. Jobs are dependent (i.e To work on the ith job, you have to finish all the jobs j where 0 <= j < i). You have to finish at lea

leetcode.com

class Solution:
    def minDifficulty(self, jobDifficulty: List[int], d: int) -> int:
        N = len(jobDifficulty)
        
        if d > N:
            return -1

        dp = [[-1] * (d+1) for _ in range(N+1)]

        INF = 987654321

        def dfs(si, d):
            if dp[si][d] != -1:
                return dp[si][d]

            if d == 1:
                return max(jobDifficulty[si:])
            
            dp[si][d] = INF

            for i in range(si, (N - d) + 1):
                dp[si][d] = min(dp[si][d], max(jobDifficulty[si:i+1]) + dfs(i+1, d-1))
        

            return dp[si][d]


        return dfs(0, d)

 

 

다른 사람들 풀이를 보는데 뭔 알아보지도 못하는것만 잔뜩 있어서 직접 올린다.

부분 문제로 바꿀 수 있으면 dp를 사용할 수 있다. 이 풀이는 dfs로 탑 다운 방식으로 풀기에 부분문제가 앞이 아닌 뒤에서부터 조금씩 만들어져서 원래 문제까지 확장한다.

 

https://leetcode.com/problems/minimum-difficulty-of-a-job-schedule/solutions/4478864/python-code-that-easy-to-read/

 

python code that easy to read - undefined - LeetCode

View sglee487's solution of undefined on LeetCode, the world's largest programming community.

leetcode.com

 

'코딩테스트 > Python' 카테고리의 다른 글

codility의 PrettyTiling 문제를 보며 느낀점  (0) 2023.02.08
파이썬 시간이 줄어드는 요소들 정리한거  (0) 2021.07.08
백준 input = sys.stdin.readline 차이  (0) 2021.07.02
'코딩테스트/Python' 카테고리의 다른 글
  • codility의 PrettyTiling 문제를 보며 느낀점
  • 파이썬 시간이 줄어드는 요소들 정리한거
  • 백준 input = sys.stdin.readline 차이
용나리
용나리
  • 용나리
    티스토리 블로그
    용나리
  • 전체
    오늘
    어제
    • 분류 전체보기 (334)
      • 과거의 것들 (93)
        • AI Tech boostcamp (92)
      • 생각정리(고찰) (2)
      • 기술 글 (1)
      • 코딩테스트 (4)
        • C++ (0)
        • Python (4)
      • CS (121)
        • 컴퓨터 시스템 (4)
        • 코틀린 인 액션 (13)
        • 김영한 스프링 강의 (104)
      • 일지 남기기용 (11)
        • 운동 (10)
      • 개발 배포 해보기 (1)
      • 프로그래밍 언어 및 기타 (32)
        • Spring Boot (9)
        • Python (9)
        • Kotlin (1)
        • Flutter (2)
        • SQL (4)
        • Docker (3)
        • 공통 (4)
      • os (4)
        • Linux (4)
      • 기술 (17)
        • PyTorch (6)
        • Computer Vision (6)
        • NLP (1)
        • 기타 (4)
      • 제품 후기 (0)
      • 게임 (0)
        • Human Resource Machine (0)
      • 강의 (26)
        • fullstackdeeplearning_sprin.. (9)
        • 부캠 안드로이드 학습정리 (17)
      • 개인 메모 (10)
      • IT 기타 (5)
      • 논문 읽기 연습 (5)
        • Computer Vision (1)
        • NLP (0)
        • 공통 (2)
        • 그냥 메모 (2)
  • 블로그 메뉴

    • 홈
    • 태그
    • 방명록
  • 링크

  • 공지사항

  • 인기 글

  • 태그

    파이썬 실행경로
    pip install killed
  • 최근 댓글

  • 최근 글

  • hELLO· Designed By정상우.v4.10.5
용나리
1335. Minimum Difficulty of a Job Schedule 풀이 python
상단으로

티스토리툴바