当前位置: 首页 > 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);
}

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

待添加

http://www.dtcms.com/a/256797.html

相关文章:

  • (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对比应用场景
  • ✨【超详细】基于 CUDA 12.4 + Python 3.11 构建 Wan2.1 项目的集成推理环境(含 PyTorch 2.5.1 GPU 安装教程)
  • 如何仅用AI开发完整的小程序<5>—让AI制作开始页面
  • 第八章 网络安全
  • uni-app项目实战笔记21--uniapp缓存的写入和读取
  • 激活函数为何能增强神经网络的非线性表达能力?
  • Excel学习02
  • #### es相关内容的索引 ####
  • Perplexity AI:对话式搜索引擎的革新者与未来认知操作系统
  • 深入解析逻辑回归算法:原理、推导与实践
  • C#Halcon从零开发_Day13_几种阈值分割方法