1883. 准时抵达会议现场的最小跳过休息次数

1883. 准时抵达会议现场的最小跳过休息次数


题目链接:1883. 准时抵达会议现场的最小跳过休息次数

代码如下:

//参考:https://leetcode.cn/problems/minimum-skips-to-arrive-at-meeting-on-time/solutions/2746611/jiao-ni-yi-bu-bu-si-kao-dong-tai-gui-hua-gxd2
class Solution {
public:
    int minSkips(vector<int>& dist, int speed, int hoursBefore) 
    {
        if(accumulate(dist.begin(),dist.end(),0)>(long long)speed*hoursBefore)
        {
            return -1;
        }
        int n=dist.size();
        vector<vector<int>> memo(n,vector<int>(n,-1));//-1代表没计算过
        function<int(int,int)> dfs=[&](int i,int j)->int
        {
            if(j<0)//递归边界
            {
                return 0;
            }
            auto &res=memo[i][j];
            if(res!=-1) return res;
            res=(dfs(i,j-1)+dist[j]+speed-1)/speed*speed;
            if(i) res=min(res,dfs(i-1,j-1)+dist[j]);
            return res;
        }; 
        for(int i=0;;i++)
        {
            if(dfs(i,n-2)+dist[n-1]<=(long long)speed*hoursBefore)
                return i;
        }
    }
};

相关推荐

  1. 1883. 准时抵达会议现场休息次数

    2024-04-25 06:24:02       16 阅读
  2. 力扣1838.高频元素频数

    2024-04-25 06:24:02       9 阅读
  3. leetcode2684--矩阵中移动次数

    2024-04-25 06:24:02       17 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-04-25 06:24:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-04-25 06:24:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-04-25 06:24:02       18 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-04-25 06:24:02       20 阅读

热门阅读

  1. MAC 安装miniconda

    2024-04-25 06:24:02       11 阅读
  2. Axios

    2024-04-25 06:24:02       10 阅读
  3. 【OceanBase系列】—— 常用 SQL

    2024-04-25 06:24:02       13 阅读
  4. FPGA中乘除法运算实现途径

    2024-04-25 06:24:02       14 阅读
  5. Feign 和 OpenFeign 的区别???

    2024-04-25 06:24:02       15 阅读
  6. 根据前,中(后,中)构建二叉树

    2024-04-25 06:24:02       10 阅读
  7. MySQL_day1

    2024-04-25 06:24:02       12 阅读