当前位置:网站首页>Minimum ticket price (day 80)
Minimum ticket price (day 80)
2022-07-27 03:40:00 【Zhangxueheng】
List of articles
1: subject
In a country where train travel is very popular , You planned some train trips a year in advance .
In the next year , The day you are going to travel will be called days The array of gives .
Each item is from 1 To 365 The integer of .
There are three different ways of selling train tickets :
A one-day pass costs costs[0] dollar ;
A seven day pass costs costs[1] dollar ;
A 30 day pass costs costs[2] dollar .
The pass allows unlimited travel for days .
for example , If we were in 2 Days to get a duration of 7 Day's pass , Then we can travel together 7 God : The first 2 God 、 The first 3 God 、 The first 4 God 、 The first 5 God 、 The first 6 God 、 The first 7 Day and day 8 God .
Return what you want to complete in the given list days The minimum cost of travel for each day listed in .
Input format
The first line contains an integer n, Express days Length of array .
The second line contains n It's an integer , Express days[i].
The third line contains 3 It's an integer , Express costs[i].
Output format
An integer , Indicates the minimum consumption required for travel .
Data range
1≤n≤365,
1≤days[i]≤365,
days Strictly increasing in order ,
1≤costs[i]≤1000.
sample input :
6
1 4 6 7 8 20
2 7 15
sample output :
11
2: Topic realization
#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;
}
边栏推荐
- The application and significance of digital twins are the main role and conceptual value of electric power.
- spark:计算不同分区中相同key的平均值(入门级-简单实现)
- Docker creates MySQL 8.x container and supports Mac and arm architecture chips
- Contour detection based on OpenCV (2)
- [learn FPGA programming from scratch -54]: high level chapter - FPGA development based on IP core - principle and configuration of PLL PLL IP core (Altera)
- Data analysis and disassembly method of banyan tree in Bairong
- Spark Learning Notes (IV) -- spark core programming RDD
- mysql底层数据结构
- Deeply understand the underlying data structure and algorithm of MySQL index
- Penetration test - post penetration - Trace cleaning
猜你喜欢

【1206. 设计跳表】

mysql底层数据结构

spark学习笔记(四)——sparkcore核心编程-RDD

复盘:DFS与BFS的主要区别,在思想上的区别,代码实现上的区别

Spark Learning Notes (IV) -- spark core programming RDD

Pytorch损失函数总结

基于OpenCV的轮廓检测(1)

快速排序及优化

Code practice when the queue reaches the maximum length

Activiti5.22.0 extension supports domestic databases, taking gbase database as an example
随机推荐
渗透测试-后渗透-痕迹清理
Introduction to database - a brief introduction to MySQL
在typora中插入图片和视频
30 minutes to thoroughly understand the synchronized lock upgrade process
Docker creates MySQL 8.x container and supports Mac and arm architecture chips
FastBoot brush machine
What are "full five unique" and "full two unique"? Any difference?
be based on. NETCORE development blog project starblog - (16) some new functions (monitoring / statistics / configuration / initialization)
volatile关键字及其作用
Does Oracle have a distributed database?
J-3-point practice in the second game of 2022 Niuke multi school
flask_restful中reqparse解析器继承
Banyan loan,
Pytoch loss function summary
redis秒杀案例,跟着b站尚硅谷老师学习
若依框架代码生成详解
数字孪生实际应用:智慧城市项目建设解决方案
客户案例 | 关注老年用户体验,银行APP适老化改造要避虚就实
The application and significance of digital twins are the main role and conceptual value of electric power.
2022牛客多校第二场的J -- 三分做法