Codeforces Round #485 (Div. 2) C. Three displays
Codeforces Round #485 (Div. 2) C. Three displays
题目连接:
http://codeforces.com/contest/987/problem/C
Description
It is the middle of 2018 and Maria Stepanovna, who lives outside Krasnokamensk (a town in Zabaikalsky region), wants to rent three displays to highlight an important problem.
There are $n$ displays placed along a road, and the $i$-th of them can display a text with font size $s_i$ only. Maria Stepanovna wants to rent such three displays with indices $i < j < k$ that the font size increases if you move along the road in a particular direction. Namely, the condition $s_i < s_j < s_k$ should be held.
The rent cost is for the $i$-th display is $c_i$. Please determine the smallest cost Maria Stepanovna should pay.
Sample Input
5
2 4 5 4 10
40 30 20 10 40
Sample Output
90
题意
找到一个三元组,组内元素为(i, j, k) ,有\(i<j<k\),问最小花费的三元组的花费为多少
Find a tuple whose elements fit the relationship \(i<j<k\). Each element has its cost.Find the mininum cost.
题解:
dp[i][o] 代表装了第i个物品后,共装了o个物品时的最小花费,dp[i][o] = min (dp[i][o],dp[k][o-1]+cost[i]); 其中 \(w[k]<w[i]\)
dp[i][o] represent we put the i-th element into the bag, after that there are \(o\) elements in the bag. The transform eqution is dp[i][o] = min (dp[i][o],dp[k][o-1]+cost[i]); in case of \(w[k]<w[i]\).
代码
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int n;
pair<int,long long> p[3010];
long long dp[3010][3];
const long long INF = 0x7ffffffffffll;
int main() {
cin>>n;
for (int i=1;i<=n;i++) {
cin>>p[i].first;
}
for (int i=1;i<=n;i++) {
cin>>p[i].second;
}
for (int i=1;i<=n;i++) {
dp[i][1]=p[i].second;
dp[i][2]=dp[i][3]=INF;
for (int o=1;o<i;o++) {
if (p[o].first<p[i].first) {
dp[i][2] = min(dp[i][2],dp[o][1]+p[i].second);
dp[i][3] = min(dp[i][3],dp[o][2]+p[i].second);
}
}
}
long long ans = INF;
for (int i=3;i<=n;i++)
ans = min(ans,dp[i][3]);
cout << (ans==INF?-1:ans) << endl;
}
Codeforces Round #485 (Div. 2) C. Three displays的更多相关文章
- Codeforces Round #485 (Div. 2)
Codeforces Round #485 (Div. 2) https://codeforces.com/contest/987 A #include<bits/stdc++.h> us ...
- Codeforces Round #485 (Div. 2) D. Fair
Codeforces Round #485 (Div. 2) D. Fair 题目连接: http://codeforces.com/contest/987/problem/D Description ...
- Codeforces Round #485 (Div. 2) F. AND Graph
Codeforces Round #485 (Div. 2) F. AND Graph 题目连接: http://codeforces.com/contest/987/problem/F Descri ...
- Codeforces Round #485 (Div. 2) E. Petr and Permutations
Codeforces Round #485 (Div. 2) E. Petr and Permutations 题目连接: http://codeforces.com/contest/987/prob ...
- Codeforces Round #485 (Div. 2) A. Infinity Gauntlet
Codeforces Round #485 (Div. 2) A. Infinity Gauntlet 题目连接: http://codeforces.com/contest/987/problem/ ...
- Codeforces Round #485 (Div. 2) C题求三元组(思维)
C. Three displays time limit per test 1 second memory limit per test 256 megabytes input standard in ...
- Codeforces Round #485 (Div. 2)-B-High School: Become Human
B. High School: Become Human time limit per test 1 second memory limit per test 256 megabytes input ...
- Codeforces Round #485 Div. 1 vp记
A:对每种商品多源bfs一下每个点到该商品的最近距离,对每个点sort一下取前s个即可. #include<iostream> #include<cstdio> #includ ...
- Codeforces Round #366 (Div. 2) ABC
Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...
随机推荐
- jquery中的 parseJSON() 源码分析
parseJSON: function( data ) { // Attempt to parse using the native JSON parser first if ( window.JSO ...
- 史上最全最详细的环境搭建教程,行百里者手把手教你在windows下搭建Anaconda+pycharm+库文件(TensorFlow,numpy)环境搭建
我是在搭建TensorFlow开发环境的道路上走了很多弯路 掉了很多头发,为了让广大同学们不在受苦受累 下面我将手把手教你学习如特快速搭建python环境 快速导入numpy,PIL,pillow,等 ...
- C++/CLI
[C++/CLI] A C++/CLI application or component uses extensions to C++ syntax (as allowed by the C++ Sp ...
- SocketIO Server
package com.fd.socketio; import org.json.JSONObject; import com.corundumstudio.socketio.AckRequest; ...
- vue axios跨域
现在应用都是前后端分离,这也造成前端在调用接口时出现跨域问题,在控制台会这样提示 ,如果有类似于此图的提示,就已经表明你的接口调用出现了跨域问题,此文章是我对于vue跨域其中一种方式的一些经验,如果错 ...
- Sprite(雪碧图)的应用
雪碧图是根据CSS sprite音译过来的,是将很多很多的小图标放在一张图片上. 使用雪碧图的目的:有时为了美观,我们会使用一张图片来代替一些小图标,但是一个网页可能有很多的小图标,浏览器在显示页面的 ...
- java实现将包含多个<REC>的文件拆成若干只包含一个<REC>的文件
遍历文件夹里的文件,将包含多个<REC>的文件拆成若干只包含一个<REC>的文件 package com.prepub; import java.io.BufferedRead ...
- Java中的equals和hashCode方法详解
Java中的equals和hashCode方法详解 转自 https://www.cnblogs.com/crazylqy/category/655181.html 参考:http://blog.c ...
- vue加elementui开发的分页显示
由于我的是公共引入样式表和css表所以,将公共的也写出来了(我接手的项目为基于vue开发的) 公共的index.html 引入js <script src="{MODULE_URL}s ...
- CentOS 7 安装与卸载MySQL 5.7
先介绍卸载 防止重装 yum方式 查看yum是否安装过mysql yum list installed mysql* 如或显示了列表,说明系统中有MySQL yum卸载 根据列表上的名字 yum re ...