当前位置:网站首页>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;
}
边栏推荐
- Textbox in easyUI inserts content at the cursor position
- How to conduct 360 assessment
- Detailed explanation of const usage in C language
- typescript ts 基础知识之接口、泛型
- The diagram of user login verification process is well written!
- volatile关键字及其作用
- Deployment of ruoyi's environment and operation of the system
- Sqlserver select * can you exclude a field
- MySQL underlying data structure
- 【1206. 设计跳表】
猜你喜欢

网络安全/渗透测试工具AWVS14.9下载/使用教程/安装教程

Mysql: summary of common sub database and sub table schemes of Internet companies

复盘:图像有哪些基本属性?关于图像的知识你知道哪些?图像的参数有哪些

Annotation summary of differences between @autowired and @resource

Contour detection based on OpenCV (1)

Customer cases | pay attention to the elderly user experience, and the transformation of bank app to adapt to aging should avoid falsehood and be practical

flask_ Reqparse parser inheritance in restful

Explain详解

Message rejected MQ

Design method and test method of APP interface use case
随机推荐
Take you to know what Web3.0 is
Explain详解
[understanding of opportunity -52]: the depth of communication varies from person to person
If the detailed explanation is generated according to the frame code
【树链剖分】2022杭电多校2 1001 Static Query on Tree
Docker creates MySQL 8.x container and supports Mac and arm architecture chips
30 minutes to thoroughly understand the synchronized lock upgrade process
智能体重秤方案主控采用CSU18M91
【树链剖分】模板题
Insert pictures and videos in typera
Technology vane | interpretation of cloud native technology architecture maturity model
JMeter distributed pressure measurement
flask_ Reqparse parser inheritance in restful
spark学习笔记(六)——sparkcore核心编程-RDD行动算子
阶乘末尾0的数量
Does Oracle have a distributed database?
How to interact with the server when the client sends an SQL message
easyui中textbox在光标位置插入内容
【正则】判断, 手机号,身份证号
MySQL的数据库有关操作