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 ...
随机推荐
- 使用MagickNet编辑图片
ImageMagick是一个免费的创建.编辑.合成图片的软件.它可以读取.转换.写入多种格式的图片.图片切割.颜色替换.各种效果的应用,图片的旋转.组合,文本,直线,多边形,椭圆,曲线 ...
- 9. maps
C++有vertor,java有HashMap,C语言想使用则需要自行封装,不同的类型还需要再封装,特别麻烦. 看看Go语言的map的使用方法:var member map[string]int,创建 ...
- python3安装pcap遇到的问题
最近想在win7上安装pypcap,遇到了一下问题,现在大概总结一下: 直接使用pip install pypcap,提示pcap.h not found: 网上下载pypcap安装包,运行pytho ...
- Huawei BGP和OSPF双边界重分布(二)
网络拓扑: 本例主要配置和例一致,主要是在AR3260-AR1和AR3260-AR2的路由域的边界上,从AR3260-AR1上重分布进BGP 65001的路由的时候打tag 650011,在AR326 ...
- Day1数据结构和算法
2019-02-27 程序设计=数据结构+算法 数据结构就是关系,是数据元素相互之间存在的关系集合 逻辑结构:数据对象中数据元素的相互关系 集合结构:集合里的数据元素除了同属于一个集合外没有其他关系 ...
- 关于为什么会涉足easyui
之前公司需要做一款类似于报价系统的功能,涉及到表单以及报表的统计, 这时分配给我,PHP也要开始弄easyui了 就这样走上了前端的路? 还挺感谢这些时间,有精力来学习额外的东西 不学习就会落后,ヾ( ...
- 控制请求重复提交的方法总结(Token)
重复提交的定义: 重复提交指的是同一个请求(请求地址和请求参数都相同)在很短的时间内多次提交至服务器,从而对服务器造成不必要的资源浪费,甚至在代码不健壮的情况还会导致程序出错. 重复提交的原因或触发事 ...
- 周一要做的事情Sd31y5YE
问实习生活动是否有费用 调查结果更新,提醒各个pm 修改模板,把我们追加的东西体现在模板里
- c++常用小算法
这篇文章列出了一些简单常用的C++容器算法,C++标准库中事实上提供了很多的算法并且有详细的介绍.如果需要详细的了解这些算法可以 参考C++在线参考手册 algrithm . 1 排序 在 #incl ...
- 使用QML绘制界面
1 使用QML设计登录界面 https://www.cnblogs.com/bhlsheji/p/5324871.html 2 使用QML实现下拉列表框 https://blog.csdn.net/ ...