专栏首页算法修养LeetCode 1723. Find Minimum Time to Finish All Jobs

LeetCode 1723. Find Minimum Time to Finish All Jobs

题目

题意:将n个数分成k组,使得k组中的最大值最小。

题解:暴力DFS,但是要注意两个地方剪枝,首先在DFS的过程中判断当前的最大值是不是已经超过了已有答案。 第二个剪枝的地方比较triky,由于我们对k组没有顺序要求的,所以当剩下的组都是空的时候,我们只需要DFS第一个组。

class Solution {
public:
  
int p[15];
int ans;
int n;
    int minimumTimeRequired(vector<int>& jobs, int k) {
        
	    n = jobs.size();
        ans=INT_MAX;
        fun(0,k,0,jobs);
        
        return ans;
    }
    
    void fun(int i, int k, int m, vector<int>& jobs)
    {
        if (i == n)
        {
            if (ans > m)
                ans = m;
            return;
        }
        
        for (int j = 0; j < k; j++)
        {
            p[j] += jobs[i];
            if (p[j] > ans)
            {
                p[j] -= jobs[i];
                
                continue;
            }
            if (p[j] > m)
                fun(i + 1, k, p[j], jobs);
            else
                fun(i + 1, k, m, jobs);
            
            p[j] -= jobs[i];
            
            if(p[j]==0)
                break;
        }
    }
};

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

我来说两句

0 条评论
登录 后参与评论

相关文章

  • HOJ 2317 Pimp My Ride(状态压缩DP)

    Pimp My Ride My Tags (Edit) Source : TUD 2005 Time limit : 3 sec Me...

    ShenduCC
  • LeetCode Weekly Contest 43解题思路

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.n...

    用户1147447
  • 【Dr.Elephant中文文档-6】度量指标和启发式算法

    我们将作业的资源使用量定义为任务容器大小和任务运行时间的乘积。因此,作业的资源使用量可以定义为mapper和reducer任务的资源使用量总和。

    一条老狗
  • 【GitLab CI/CD】:Pipelines

    Pipelines are the top-level component of continuous integration, delivery, and d...

    WEBJ2EE
  • Baozi Training Leetcode solution 135: Candy

    Blogger:https://blog.baozitraining.org/2019/11/leetcode-solution-135-candy.html

    包子面试培训
  • Simulate a Windows Service using ASP.NET to run scheduled jobs

    Introduction How to run scheduled jobs from ASP.NET without requiring a Windows ...

    阿新
  • 多机调度的几何

    摘要:我们考虑以下一般调度问题:在时间0处有m个相同的机器和n个作业都被释放。每个作业j具有处理时间pj,以及指定j的成本的任意非递减函数fj,对于每个可能的完...

    罗大琦
  • 九度OJ——1154Jungle Roads

    The Head Elder of the tropical island of Lagrishan has a problem. A burst of ...

    AI那点小事
  • LeetCode Weekly Contest 38解题思路

    版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.n...

    用户1147447
  • uva----(10794) A Different Task

     A Different Task  The (Three peg) Tower of Hanoi problem is a popular ...

    Gxjun
  • python 多cpu并行编程

    py3study
  • How to find “hidden” remote jobs using Google Search.

    By using a special search operator with Google search, you can find remote jobs ...

    仇诺伊
  • 关关的刷题日记82 – Leetcode 453. Minimum Moves to Equal Array Elements

    关关的刷题日记82 – Leetcode 453. Minimum Moves to Equal Array Elements 题目 Given a non-e...

    WZEARW
  • codeforce893C (并查集)

    Vova promised himself that he would never play computer games… But recently Fire...

    dejavu1zz
  • leetcode502. IPO

    Suppose LeetCode will start its IPO soon. In order to sell a good price of its s...

    眯眯眼的猫头鹰
  • Azkaban 2.5 Documentation

    Azkaban was implemented at LinkedIn to solve the problem of Hadoop job dependenc...

    WindWant
  • 完全停止Oracle中正在运行的JOB

    源地址:http://www.quest-pipelines.com/newsletter-v4/0403_C.htm

    用户1148526
  • Leetcode solution 270: Closest Binary Search Tree Value

    WE ARE HIRING! Software engineer interviewers from Amazon, Facebook and Twitter....

    包子面试培训
  • 图论--差分约束--HDU\HDOJ 4109 Instrction Arrangement

    Ali has taken the Computer Organization and Architecture course this term. He l...

    风骨散人Chiam

扫码关注云+社区

领取腾讯云代金券