当前位置: 首页 > news >正文

【力扣 中等 C】983. 最低票价

目录

题目

解法一:动态规划(递归)

解法二:动态规划(迭代)


题目

待添加

解法一:动态规划(递归)

int min(int a, int b)
{return a < b ? a : b;
}int f(const int* days, int size1, const int* costs, const int* cDays, int size2,int index, int* dp)
{if (index == size1)return 0;if (dp[index] != INT_MAX)return dp[index];for (int i = 0; i < 3; i++){int nextIndex = index;while (nextIndex < size1 && days[index] + cDays[i] > days[nextIndex])nextIndex++;dp[index] = min(dp[index], costs[i] + f(days, size1, costs, cDays, size2, nextIndex, dp));}return dp[index];
}int compute(const int* days, int size1, const int* costs, int size2)
{const int cDays[3] = {1, 7, 30};int* dp = malloc(sizeof(*dp) * size1);for (int i = 0; i < size1; i++)dp[i] = INT_MAX;int minCharge = f(days, size1, costs, cDays, size2, 0, dp);free(dp);return minCharge;
}int mincostTickets(int* days, int daysSize, int* costs, int costsSize)
{return compute(days, daysSize, costs, costsSize);
}

解法二:动态规划(迭代)

待添加

相关文章:

  • (LeetCode 面试经典 150 题 ) 189. 轮转数组(字符串、双指针)
  • [linux] Ubuntu 24软件下载和安装汇总(自用)
  • Linux安全基石:Shell运行原理与权限管理系统解读
  • 【Docker基础】Docker容器管理:docker run及其参数详解
  • Python 使用 Requests 模块进行爬虫
  • 学习设计模式《十四》——组合模式
  • dijkstra(迪杰斯特拉)算法详解
  • 阿里云CentOS系统搭建全攻略:开启云端技术之旅
  • bash的配置文件,source
  • 云函数调测、部署及日志查看
  • VSCode性能调优:从卡顿到丝滑的终极方案
  • 颠覆传统接口测试!用 Streamlit + SQLite + GPT 打造可视化自动化平台
  • 计算鱼眼相机的内参矩阵和畸变系数方法
  • SSL过期自动续签脚本-腾讯云
  • 【后端】负载均衡
  • YSYX学习记录(十一)
  • Node.js爬虫 CheerioJS ‌轻量级解析、操作和渲染HTML及XML文档
  • 深度解析云计算网络架构:VLAN+OVS+Bonding构建高可靠虚拟化平台
  • 将Linux装进口袋: Ubuntu to Go 制作
  • 【编程语言】javascript、java、go对比应用场景
  • 网站建设肆金手指排名7/女生seo专员很难吗为什么
  • 石碣网站建设/免费合作推广
  • 广东制作公司网站/seo新人培训班
  • 南京专业网站设计哪个品牌/关键词seo排名公司
  • 网站建设外包价格/网站优化公司哪个好
  • 开个网站建设公司多少钱/网络服务包括