当前位置:网站首页>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;
}
边栏推荐
- PyCharm中Debug模式进行调试详解
- Spark: calculate the average value of the same key in different partitions (entry level - simple implementation)
- 768. Block II greed that can complete sorting at most
- The new version of Alibaba Seata finally solves the idempotence, suspension and empty rollback problems of TCC mode
- spark学习笔记(六)——sparkcore核心编程-RDD行动算子
- 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
- Volatile keyword and its function
- The function and application of lpci-252 universal PCI interface can card
- Win10/win11 lossless expansion of C disk space, cross disk consolidation of C and e disks
- Annotation summary of differences between @autowired and @resource
猜你喜欢

Spark: calculate the average value of the same key in different partitions (entry level - simple implementation)

Quick sequencing and optimization

深入理解Mysql索引底层数据结构与算法

The diagram of user login verification process is well written!

数字孪生应用及意义对电力的主要作用,概念价值。

数字孪生实际应用:智慧城市项目建设解决方案

Spark Learning Notes (V) -- spark core core programming RDD conversion operator

redis秒杀案例,跟着b站尚硅谷老师学习

How to interact with the server when the client sends an SQL message

Explain tool actual operation
随机推荐
768. Block II greed that can complete sorting at most
477-82(236、61、47、74、240、93)
Pytoch loss function summary
Banyan data model of Bairong
Penetration test - post penetration - Trace cleaning
Safe-arc/warner power supply maintenance xenon lamp power supply maintenance analysis
Comprehensive care analysis lyriq Ruige battery safety design
spark:地区广告点击量排行统计(小案例)
Explain详解
Leetcode 207. curriculum (July 26, 2022)
Spark Learning Notes (IV) -- spark core programming RDD
Redis spike case, learn from Shang Silicon Valley teacher in station B
Member array and pointer in banyan loan C language structure
typescript ts 基础知识之接口、泛型
Redis source code learning (33), command execution process
J-3-point practice in the second game of 2022 Niuke multi school
Wechat applet generation Excel
How to optimize MySQL
[understanding of opportunity -52]: the depth of communication varies from person to person
How to interact with the server when the client sends an SQL message