当前位置:网站首页>最低票价(DAY 80)
最低票价(DAY 80)
2022-07-27 01:06:00 【张学恒】
1:题目
在一个火车旅行很受欢迎的国度,你提前一年计划了一些火车旅行。
在接下来的一年里,你要旅行的日子将以一个名为 days 的数组给出。
每一项是一个从 1 到 365 的整数。
火车票有三种不同的销售方式:
一张为期一天的通行证售价为 costs[0] 美元;
一张为期七天的通行证售价为 costs[1] 美元;
一张为期三十天的通行证售价为 costs[2] 美元。
通行证允许数天无限制的旅行。
例如,如果我们在第 2 天获得一张为期 7 天的通行证,那么我们可以连着旅行 7 天:第 2 天、第 3 天、第 4 天、第 5 天、第 6 天、第 7 天和第 8 天。
返回你想要完成在给定的列表 days 中列出的每一天的旅行所需要的最低消费。
输入格式
第一行包含一个整数 n,表示 days 数组的长度。
第二行包含 n 个整数,表示 days[i]。
第三行包含 3 个整数,表示 costs[i]。
输出格式
一个整数,表示旅行所需要的最低消费。
数据范围
1≤n≤365,
1≤days[i]≤365,
days 按顺序严格递增,
1≤costs[i]≤1000。
输入样例:
6
1 4 6 7 8 20
2 7 15
输出样例:
11
2:题目实现
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
const int N = 400;
int n;
int days[N], f[N];
int c1, c7, c30;
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ ) cin >> days[i];
cin >> c1 >> c7 >> c30;
for (int i = 1, j7 = 0, j30 = 0; i <= n; i ++ )
{
while (days[i] - days[j7 + 1] >= 7) j7 ++ ;
while (days[i] - days[j30 + 1] >= 30) j30 ++ ;
f[i] = min({
f[i - 1] + c1, f[j7] + c7, f[j30] + c30});
}
cout << f[n] << endl;
return 0;
}
边栏推荐
猜你喜欢

浅浅梳理一下双轴快排(DualPivotQuickSort)

八皇后编程实现

Plato Farm全新玩法,套利ePLATO稳获超高收益

196. 删除重复的电子邮箱

毕业2年转行软件测试获得12K+,不考研月薪过万的梦想实现了

setTimeout第一个参数应该注意的地方

周全的照护 解析LYRIQ锐歌电池安全设计

Plato Farm全新玩法,套利ePLATO稳获超高收益
全网最全的软件测试基础知识整理(新手入门必学)

Worth more than 100 million! The 86 version of "red boy" refuses to be a Daocheng Xueba. He is already a doctor of the Chinese Academy of Sciences and has 52 companies under his name
随机推荐
力扣(LeetCode)207. 课程表(2022.07.26)
周全的照护 解析LYRIQ锐歌电池安全设计
抖音服务器带宽有多大,才能供上亿人同时刷?
[paper]PointLaneNet论文浅析
【flask】服务端获取客户端的请求头信息
Play a parallel multithreaded mcu-mc3172
On the prototype of constructor
OpenTelemetry 在服务网格架构下的最佳实践
Plato Farm通过LaaS协议Elephant Swap,为社区用户带来全新体验
如何使用DevExpress WPF在WinUI中创建第一个MVVM应用程序?
Thread.Sleep(0)的作用
八皇后编程实现
CS224W fall 课程 ---- 1.1 why Graphs ?
[哈希表] 刷题合集
Call jshaman's Web API interface to realize JS code encryption.
{“errcode“:44001,“errmsg“:“empty media data, hint: [1655962096234893527769663], from ip: 222.72.xxx.
Use the most primitive method to manually implement the common 20 array methods
After two years of graduation, I switched to software testing and got 12k+, and my dream of not taking the postgraduate entrance examination with a monthly salary of more than 10000 was realized
从ACL 2022 Onsite经历看NLP热点
数据库红的表如何设计才能使性能更加优化