当前位置:网站首页>4518. Minimum ticket price
4518. Minimum ticket price
2022-07-28 15:13:00 【Pursue people far away】
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
Code :
/* f [ i ] For the former i Days , Minimum cost required We can divide sets into three categories : (1) On this day days [ i ] Buy a one-day ticket alone , The answer is f [ i ] = f [ i - 1 ] + costs [ 0 ]; (2) Find out about the current i The difference between the latest and just enough days is more than 7 Subscript of day j, Then the front cost is f [ j ], Plus the expenses in the last seven days costs [ 1 ], namely f [ i ] = f [ j ] + costs [ 1 ]; (3) Find out about the current i The difference between the latest and just enough days is more than 30 Subscript of day k, Then the front cost is f [ k ], Plus the expenses in the last 30 days costs [ 2 ], namely f [ i ] = f [ k ] + costs [ 2 ]; Yes 2 Three situations in , We take a minimum value is the answer */
#include <bits/stdc++.h>
using namespace std;
const int N = 400;
int n;
int d[N], f[N], c[3];
int find(int r, int limit)
{
int l = r;
while (l && d[r] - d[l] + 1 <= limit)// Go back to find the closest to the current subscript and just meet the number of days, with a difference of more than limit The subscript , But the limit is 1
l--;
return l;
}
int main()
{
cin >> n;
for (int i = 1; i <= n; i++)
cin >> d[i];
for (int i = 0; i < 3; i++)
cin >> c[i];
int res1, res2;
for (int i = 1; i <= n; i++)
{
f[i] += f[i - 1] + c[0];
res1 = f[find(i, 7)] + c[1];
res2 = f[find(i, 30)] + c[2];
int t = min(res1, res2);
f[i] = min(f[i], t);
}
cout << f[n] << endl;
return 0;
}
边栏推荐
- pyppeteer 遇到的问题
- 安全与隐私计算在国内发展现状
- Find papers and their open source code
- volatile原理
- Install biological sequence de redundancy software CD hit
- SQL labs detailed problem solving process (less1-less10)
- Examples of Pareto optimality and Nash equilibrium
- 【游戏测试工程师】初识游戏测试—你了解它吗?
- Introduction to mqtt protocol
- 3、 C language storage class
猜你喜欢

Chapter 3 stack, queue and array

滑块还原和验证(法律数据库)

经典Dijkstra与最长路

buuctf_ php

2021-09-02

Mysql使用left join连表查询时,因连接条件未加索引导致查询很慢

Knowledge map Foundation (I) - what is knowledge map
![[complete installation package & tutorial] sqlserver basic installation_ Sqlserver completely uninstalled_ Sqlserver custom installation_ Getting started with sqlserver_ SQLSERVER database](/img/72/d3e46a820796a48b458cd2d0a18f8f.png)
[complete installation package & tutorial] sqlserver basic installation_ Sqlserver completely uninstalled_ Sqlserver custom installation_ Getting started with sqlserver_ SQLSERVER database

The automatic prompt of vs code code is missing - a tick to solve it

DataTables warning: table id=campaignTable - Cannot reinitialise DataTable.解决
随机推荐
安全与隐私计算在国内发展现状
3511. 倒水问题
svg 验证码识别体验
Image steganography method
Some considerations for installing Oracle11g
4519. 正方形数组的数目
3438. Number system conversion
14、 ROS meta function package
Buuctf partial solution
When MySQL uses left join to query tables, the query is slow because the connection conditions are not properly guided
CCSP 云安全设计原则都有哪些
Pytorch GPU installation
汇编学习
What is the difference between UTF-8, utf-16 and UTF-32 character encoding? [graphic explanation]
QT qlineedit, qtextedit, qplaintextedit differences
JS study notes 18-23
PS modify the length and width pixels and file size of photos
SystemVerilog
Three pop-up boxes commonly used in JS
pyppeteer 遇到的问题