作业调度的最大利润

问题描述 投票:0回答:0

我正在解决问题

作业调度的最大利润 https://leetcode.com/problems/maximum-profit-in-job-scheduling/submissions/

如何使用 dp 数组来记忆它

请帮帮我

class Solution:
    def fun(self,index,prevend,ans,n):
        if index>=n:
            return 0
        
        if prevend>ans[index][0]:
            return self.fun(index+1,prevend,ans,n)
        cost=0        
        cost=max(self.fun(index+1,prevend,ans,n),ans[index][2]+self.fun(index+1,ans[index][1],ans,n))
        return cost
    def jobScheduling(self, startTime: List[int], endTime: List[int], profit: List[int]) -> int:
        combine = zip(startTime, endTime, profit)
        ans = sorted(combine, key=lambda x: x[1])

        return self.fun(0,0,ans,len(ans))
python-3.x recursion dynamic-programming greedy
© www.soinside.com 2019 - 2024. All rights reserved.