当前位置:网站首页>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;
}
边栏推荐
- Explain详解
- 微信小程序生成Excel
- Docker creates MySQL 8.x container and supports Mac and arm architecture chips
- Activiti5.22.0 extension supports domestic databases, taking gbase database as an example
- Mysql database related operations
- 【无标题】JDBC连接数据库读超时
- Pytoch loss function summary
- typescript ts 基础知识之接口、泛型
- Fastboot刷机
- 渗透测试-后渗透-痕迹清理
猜你喜欢

Indexing best practices

Activiti5.22.0 extension supports domestic databases, taking gbase database as an example

How many implementation postures of delay queue? Daily essential skills!

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

MySQL的数据库有关操作

Explain

Take you to know what Web3.0 is

若依框架代码生成详解
![[1206. Design skip table]](/img/a9/ca45c9fedd6e48387821bdc7ec625c.png)
[1206. Design skip table]

Basic concept and essence of Architecture
随机推荐
复盘:图像有哪些基本属性?关于图像的知识你知道哪些?图像的参数有哪些
将幕布文章OPML转换为Markdown的方法
Spark Learning Notes (IV) -- spark core programming RDD
Database usage security policy
基于OpenCV的轮廓检测(2)
快速排序及优化
复盘:DFS与BFS的主要区别,在思想上的区别,代码实现上的区别
Quick sequencing and optimization
MySQL中文失败问题
Volatile keyword and its function
Data analysis and disassembly method of banyan tree in Bairong
Learn the recycling mechanism of recyclerview again
Take you to know what Web3.0 is
768. 最多能完成排序的块 II 贪心
Explain详解
MySQL的数据库有关操作
Banyan data model of Bairong
Message rejected MQ
Spark: calculate the average value of the same key in different partitions (entry level - simple implementation)
深入理解Mysql索引底层数据结构与算法